Skip to content

Commit

Permalink
Rename package Carbon -> Core, per carbon-language#2113.
Browse files Browse the repository at this point in the history
  • Loading branch information
zygoloid committed Mar 19, 2024
1 parent bbe57f5 commit 0dd01fa
Show file tree
Hide file tree
Showing 23 changed files with 466 additions and 401 deletions.
7 changes: 3 additions & 4 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,8 @@ class ImportRefResolver {
const SemIR::Interface& import_interface)
-> SemIR::ConstantId {
auto interface_decl = SemIR::InterfaceDecl{SemIR::TypeId::Invalid,
SemIR::InterfaceId::Invalid,
SemIR::InstBlockId::Empty};
SemIR::InterfaceId::Invalid,
SemIR::InstBlockId::Empty};
auto interface_decl_id =
context_.AddPlaceholderInst({Parse::NodeId::Invalid, interface_decl});

Expand All @@ -696,8 +696,7 @@ class ImportRefResolver {
interface_decl_id, {Parse::NodeId::Invalid, interface_decl});

// Set the constant value for the imported interface.
auto interface_const_id =
context_.constant_values().Get(interface_decl_id);
auto interface_const_id = context_.constant_values().Get(interface_decl_id);
import_ir_constant_values_.Set(inst_id, interface_const_id);
return interface_const_id;
}
Expand Down
20 changes: 10 additions & 10 deletions toolchain/check/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

namespace Carbon::Check {

// Returns the scope of the Carbon package, or Invalid if it's not found.
// Returns the scope of the Core package, or Invalid if it's not found.
//
// TODO: Consider tracking the Carbon package in SemIR so we don't need to use
// TODO: Consider tracking the Core package in SemIR so we don't need to use
// name lookup to find it.
static auto GetCarbonPackage(Context& context, Parse::AnyExprId node_id)
static auto GetCorePackage(Context& context, Parse::AnyExprId node_id)
-> SemIR::NameScopeId {
// TODO: If the current package is the `Carbon` package, return
// TODO: If the current package is the `Core` package, return
// `SemIR::InstId::Package`.

auto ident_id = context.identifiers().Lookup("Carbon");
auto ident_id = context.identifiers().Lookup("Core");
if (!ident_id.is_valid()) {
return SemIR::NameScopeId::Invalid;
}
auto name_id = SemIR::NameId::ForIdentifier(ident_id);

// Look up `package.Carbon`.
// Look up `package.Core`.
auto package_id = context.LookupQualifiedName(
node_id, name_id, SemIR::NameScopeId::Package, /*required=*/false);
if (!package_id.is_valid()) {
Expand All @@ -40,7 +40,7 @@ static auto GetCarbonPackage(Context& context, Parse::AnyExprId node_id)
if (auto package_inst =
context.insts().TryGetAs<SemIR::Namespace>(package_id)) {
auto& name_scope = context.name_scopes().Get(package_inst->name_scope_id);
// Check that this is really the `Carbon` package and not an alias.
// Check that this is really the `Core` package and not an alias.
if (name_scope.is_closed_import && name_scope.name_id == name_id &&
name_scope.enclosing_scope_id == SemIR::NameScopeId::Package) {
return package_inst->name_scope_id;
Expand All @@ -50,15 +50,15 @@ static auto GetCarbonPackage(Context& context, Parse::AnyExprId node_id)
}

// Returns the name scope of the operator interface for the specified operator
// from the Carbon package.
// from the Core package.
static auto GetOperatorInterface(Context& context, Parse::AnyExprId node_id,
Operator op) -> SemIR::NameScopeId {
auto carbon_package_id = GetCarbonPackage(context, node_id);
auto carbon_package_id = GetCorePackage(context, node_id);
if (!carbon_package_id.is_valid()) {
return SemIR::NameScopeId::Invalid;
}

// Lookup `Carbon.InterfaceName`.
// Lookup `Core.InterfaceName`.
auto interface_ident_id = context.identifiers().Add(op.interface_name);
auto interface_id = context.LookupQualifiedName(
node_id, SemIR::NameId::ForIdentifier(interface_ident_id),
Expand Down
58 changes: 43 additions & 15 deletions toolchain/check/testdata/interface/import.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,17 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT: %.2: type = tuple_type () [template]
// CHECK:STDOUT: %.3: type = interface_type @Basic [template]
// CHECK:STDOUT: %.4: type = interface_type @ForwardDeclared [template]
// CHECK:STDOUT: %.5: type = ptr_type ForwardDeclared [template]
// CHECK:STDOUT: %.6: type = struct_type {.f: ForwardDeclared} [template]
// CHECK:STDOUT: %.7: type = struct_type {.f: ()} [template]
// CHECK:STDOUT: %.5: type = assoc_entity_type @Basic, type [template]
// CHECK:STDOUT: %.6: <associated type in Basic> = assoc_entity element0, file.%import_ref.5 [template]
// CHECK:STDOUT: %.7: type = assoc_entity_type @Basic, <function> [template]
// CHECK:STDOUT: %.8: <associated <function> in Basic> = assoc_entity element1, file.%import_ref.6 [template]
// CHECK:STDOUT: %.9: type = assoc_entity_type @ForwardDeclared, type [template]
// CHECK:STDOUT: %.10: <associated type in ForwardDeclared> = assoc_entity element0, file.%import_ref.7 [template]
// CHECK:STDOUT: %.11: type = assoc_entity_type @ForwardDeclared, <function> [template]
// CHECK:STDOUT: %.12: <associated <function> in ForwardDeclared> = assoc_entity element1, file.%import_ref.8 [template]
// CHECK:STDOUT: %.13: type = ptr_type ForwardDeclared [template]
// CHECK:STDOUT: %.14: type = struct_type {.f: ForwardDeclared} [template]
// CHECK:STDOUT: %.15: type = struct_type {.f: ()} [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
Expand All @@ -134,7 +142,11 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT: .UseEmpty = %UseEmpty
// CHECK:STDOUT: .UseBasic = %UseBasic
// CHECK:STDOUT: .UseForwardDeclared = %UseForwardDeclared
// CHECK:STDOUT: .f = %f.loc10
// CHECK:STDOUT: .UseBasicT = %UseBasicT
// CHECK:STDOUT: .UseBasicF = %UseBasicF
// CHECK:STDOUT: .UseForwardDeclaredT = %UseForwardDeclaredT
// CHECK:STDOUT: .UseForwardDeclaredF = %UseForwardDeclaredF
// CHECK:STDOUT: .f = %f.loc16
// CHECK:STDOUT: }
// CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.1]
// CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+4, used [template = constants.%.3]
Expand All @@ -148,7 +160,7 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT: }
// CHECK:STDOUT: %UseBasic: <function> = fn_decl @UseBasic [template] {
// CHECK:STDOUT: %Basic.decl: invalid = interface_decl @Basic [template = constants.%.3] {}
// CHECK:STDOUT: %Basic.ref: type = name_ref Basic, %import_ref.2 [template = constants.%.3]
// CHECK:STDOUT: %Basic.ref.loc7: type = name_ref Basic, %import_ref.2 [template = constants.%.3]
// CHECK:STDOUT: %e.loc7_13.1: Basic = param e
// CHECK:STDOUT: @UseBasic.%e: Basic = bind_name e, %e.loc7_13.1
// CHECK:STDOUT: }
Expand All @@ -158,10 +170,26 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT: %f.loc8_23.1: ForwardDeclared = param f
// CHECK:STDOUT: @UseForwardDeclared.%f: ForwardDeclared = bind_name f, %f.loc8_23.1
// CHECK:STDOUT: }
// CHECK:STDOUT: %ForwardDeclared.ref.loc10: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
// CHECK:STDOUT: %.loc10: type = ptr_type ForwardDeclared [template = constants.%.5]
// CHECK:STDOUT: %Basic.ref.loc10: type = name_ref Basic, %import_ref.2 [template = constants.%.3]
// CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+7, unused
// CHECK:STDOUT: %T.ref.loc10: <associated type in Basic> = name_ref T, @Basic.%import_ref.3 [template = constants.%.6]
// CHECK:STDOUT: %UseBasicT: <associated type in Basic> = bind_alias UseBasicT, @Basic.%import_ref.3 [template = constants.%.6]
// CHECK:STDOUT: %Basic.ref.loc11: type = name_ref Basic, %import_ref.2 [template = constants.%.3]
// CHECK:STDOUT: %import_ref.6 = import_ref ir1, inst+11, unused
// CHECK:STDOUT: %F.ref.loc11: <associated <function> in Basic> = name_ref F, @Basic.%import_ref.2 [template = constants.%.8]
// CHECK:STDOUT: %UseBasicF: <associated <function> in Basic> = bind_alias UseBasicF, @Basic.%import_ref.2 [template = constants.%.8]
// CHECK:STDOUT: %ForwardDeclared.ref.loc13: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
// CHECK:STDOUT: %import_ref.7 = import_ref ir1, inst+19, unused
// CHECK:STDOUT: %T.ref.loc13: <associated type in ForwardDeclared> = name_ref T, @ForwardDeclared.%import_ref.3 [template = constants.%.10]
// CHECK:STDOUT: %UseForwardDeclaredT: <associated type in ForwardDeclared> = bind_alias UseForwardDeclaredT, @ForwardDeclared.%import_ref.3 [template = constants.%.10]
// CHECK:STDOUT: %ForwardDeclared.ref.loc14: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
// CHECK:STDOUT: %import_ref.8 = import_ref ir1, inst+23, unused
// CHECK:STDOUT: %F.ref.loc14: <associated <function> in ForwardDeclared> = name_ref F, @ForwardDeclared.%import_ref.2 [template = constants.%.12]
// CHECK:STDOUT: %UseForwardDeclaredF: <associated <function> in ForwardDeclared> = bind_alias UseForwardDeclaredF, @ForwardDeclared.%import_ref.2 [template = constants.%.12]
// CHECK:STDOUT: %ForwardDeclared.ref.loc16: type = name_ref ForwardDeclared, %import_ref.3 [template = constants.%.4]
// CHECK:STDOUT: %.loc16: type = ptr_type ForwardDeclared [template = constants.%.13]
// CHECK:STDOUT: %f.var: ref ForwardDeclared* = var f
// CHECK:STDOUT: %f.loc10: ref ForwardDeclared* = bind_name f, %f.var
// CHECK:STDOUT: %f.loc16: ref ForwardDeclared* = bind_name f, %f.var
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: interface @Empty {
Expand All @@ -174,8 +202,8 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT:
// CHECK:STDOUT: interface @Basic {
// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+6, unused
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+13, unused
// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+9, unused
// CHECK:STDOUT: %import_ref.2: <associated <function> in Basic> = import_ref ir1, inst+13, used [template = constants.%.8]
// CHECK:STDOUT: %import_ref.3: <associated type in Basic> = import_ref ir1, inst+9, used [template = constants.%.6]
// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+7, unused
// CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+11, unused
// CHECK:STDOUT:
Expand All @@ -188,8 +216,8 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT:
// CHECK:STDOUT: interface @ForwardDeclared {
// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+18, unused
// CHECK:STDOUT: %import_ref.2 = import_ref ir1, inst+25, unused
// CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+21, unused
// CHECK:STDOUT: %import_ref.2: <associated <function> in ForwardDeclared> = import_ref ir1, inst+25, used [template = constants.%.12]
// CHECK:STDOUT: %import_ref.3: <associated type in ForwardDeclared> = import_ref ir1, inst+21, used [template = constants.%.10]
// CHECK:STDOUT: %import_ref.4 = import_ref ir1, inst+19, unused
// CHECK:STDOUT: %import_ref.5 = import_ref ir1, inst+23, unused
// CHECK:STDOUT:
Expand Down Expand Up @@ -218,9 +246,9 @@ var f: ForwardDeclared* = &f_ref.f;
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %f_ref.ref: ref {.f: ForwardDeclared} = name_ref f_ref, file.%import_ref.4
// CHECK:STDOUT: %.loc10_33: ref ForwardDeclared = struct_access %f_ref.ref, element0
// CHECK:STDOUT: %.loc10_27: ForwardDeclared* = addr_of %.loc10_33
// CHECK:STDOUT: assign file.%f.var, %.loc10_27
// CHECK:STDOUT: %.loc16_33: ref ForwardDeclared = struct_access %f_ref.ref, element0
// CHECK:STDOUT: %.loc16_27: ForwardDeclared* = addr_of %.loc16_33
// CHECK:STDOUT: assign file.%f.var, %.loc16_27
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
32 changes: 16 additions & 16 deletions toolchain/check/testdata/operators/overloaded/add.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// --- prelude.carbon

package Carbon api;
package Core api;

interface Add {
fn Op[self: Self](other: Self) -> Self;
Expand All @@ -21,16 +21,16 @@ interface AddAssign {

package User api;

import Carbon;
import Core;

class C {};

impl C as Carbon.Add {
impl C as Core.Add {
fn Op[self: C](other: C) -> C {
return {};
}
}
impl C as Carbon.AddAssign {
impl C as Core.AddAssign {
fn Op[addr self: C*](other: C) {}
}

Expand All @@ -46,7 +46,7 @@ fn TestAssign(a: C*, b: C) {

package FailNoImpl api;

import Carbon;
import Core;

class D {};

Expand All @@ -68,11 +68,11 @@ fn TestAssign(a: D*, b: D) {

package FailNoImplForArgs api;

import Carbon;
import Core;

class C {};

impl C as Carbon.Add {
impl C as Core.Add {
fn Op[self: C](other: C) -> C {
return {};
}
Expand Down Expand Up @@ -194,23 +194,23 @@ fn TestLhsBad(a: D, b: C) -> C {
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Carbon = %Carbon
// CHECK:STDOUT: .Core = %Core
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: .TestOp = %TestOp
// CHECK:STDOUT: .TestAssign = %TestAssign
// CHECK:STDOUT: }
// CHECK:STDOUT: %Carbon: <namespace> = namespace [template] {}
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
// CHECK:STDOUT: impl_decl @impl.1 {
// CHECK:STDOUT: %C.ref.loc8: type = name_ref C, %C.decl [template = constants.%C]
// CHECK:STDOUT: %Carbon.ref.loc8: <namespace> = name_ref Carbon, %Carbon [template = %Carbon]
// CHECK:STDOUT: %Core.ref.loc8: <namespace> = name_ref Core, %Core [template = %Core]
// CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+1, used [template = constants.%.2]
// CHECK:STDOUT: %Add.decl: invalid = interface_decl @Add [template = constants.%.2] {}
// CHECK:STDOUT: %Add.ref: type = name_ref Add, %import_ref.1 [template = constants.%.2]
// CHECK:STDOUT: }
// CHECK:STDOUT: impl_decl @impl.2 {
// CHECK:STDOUT: %C.ref.loc13: type = name_ref C, %C.decl [template = constants.%C]
// CHECK:STDOUT: %Carbon.ref.loc13: <namespace> = name_ref Carbon, %Carbon [template = %Carbon]
// CHECK:STDOUT: %Core.ref.loc13: <namespace> = name_ref Core, %Core [template = %Core]
// CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+22, used [template = constants.%.7]
// CHECK:STDOUT: %AddAssign.decl: invalid = interface_decl @AddAssign [template = constants.%.7] {}
// CHECK:STDOUT: %AddAssign.ref: type = name_ref AddAssign, %import_ref.2 [template = constants.%.7]
Expand Down Expand Up @@ -361,12 +361,12 @@ fn TestLhsBad(a: D, b: C) -> C {
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Carbon = %Carbon
// CHECK:STDOUT: .Core = %Core
// CHECK:STDOUT: .D = %D.decl
// CHECK:STDOUT: .TestOp = %TestOp
// CHECK:STDOUT: .TestAssign = %TestAssign
// CHECK:STDOUT: }
// CHECK:STDOUT: %Carbon: <namespace> = namespace [template] {}
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
// CHECK:STDOUT: %TestOp: <function> = fn_decl @TestOp [template] {
// CHECK:STDOUT: %D.ref.loc8_14: type = name_ref D, %D.decl [template = constants.%D]
Expand Down Expand Up @@ -454,17 +454,17 @@ fn TestLhsBad(a: D, b: C) -> C {
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Carbon = %Carbon
// CHECK:STDOUT: .Core = %Core
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: .D = %D.decl
// CHECK:STDOUT: .TestRhsBad = %TestRhsBad
// CHECK:STDOUT: .TestLhsBad = %TestLhsBad
// CHECK:STDOUT: }
// CHECK:STDOUT: %Carbon: <namespace> = namespace [template] {}
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
// CHECK:STDOUT: impl_decl @impl {
// CHECK:STDOUT: %C.ref.loc8: type = name_ref C, %C.decl [template = constants.%C]
// CHECK:STDOUT: %Carbon.ref: <namespace> = name_ref Carbon, %Carbon [template = %Carbon]
// CHECK:STDOUT: %Core.ref: <namespace> = name_ref Core, %Core [template = %Core]
// CHECK:STDOUT: %import_ref: type = import_ref ir1, inst+1, used [template = constants.%.2]
// CHECK:STDOUT: %Add.decl: invalid = interface_decl @Add [template = constants.%.2] {}
// CHECK:STDOUT: %Add.ref: type = name_ref Add, %import_ref [template = constants.%.2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ HEADER

// --- prelude.carbon

package Carbon api;
package Core api;

interface INTERFACE {
fn Op[self: Self](other: Self) -> Self;
Expand All @@ -21,16 +21,16 @@ interface INTERFACEAssign {

package User api;

import Carbon;
import Core;

class C {};

impl C as Carbon.INTERFACE {
impl C as Core.INTERFACE {
fn Op[self: C](other: C) -> C {
return {};
}
}
impl C as Carbon.INTERFACEAssign {
impl C as Core.INTERFACEAssign {
fn Op[addr self: C*](other: C) {}
}

Expand All @@ -46,7 +46,7 @@ fn TestAssign(a: C*, b: C) {

package FailNoImpl api;

import Carbon;
import Core;

class D {};

Expand All @@ -62,11 +62,11 @@ fn TestAssign(a: D*, b: D) {

package FailNoImplForArgs api;

import Carbon;
import Core;

class C {};

impl C as Carbon.INTERFACE {
impl C as Core.INTERFACE {
fn Op[self: C](other: C) -> C {
return {};
}
Expand Down
Loading

0 comments on commit 0dd01fa

Please sign in to comment.