Skip to content

Commit

Permalink
Rename template constant -> concrete constant. (carbon-language#4939)
Browse files Browse the repository at this point in the history
This implements a direction decided in a
[recent
discussion](https://docs.google.com/document/d/1Iut5f2TQBrtBNIduF4vJYOKfw7MbS8xH_J01_Q4e6Rk/edit?resourcekey=0-mc_vh5UzrzXfU4kO-3tOjA&tab=t.0#heading=h.mas1g68xx9ct)
to switch away from "template constant" when naming a constant that
doesn't depend on any generic parameters, because that creates confusion
with template-dependent constant values that depend on a template
parameter.
  • Loading branch information
zygoloid authored Feb 12, 2025
1 parent 188821b commit c6d35e1
Show file tree
Hide file tree
Showing 674 changed files with 35,168 additions and 35,168 deletions.
4 changes: 2 additions & 2 deletions toolchain/check/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ Context::Context(DiagnosticEmitter* emitter,
// Map the builtin `<error>` and `type` type constants to their corresponding
// special `TypeId` values.
type_ids_for_type_constants_.Insert(
SemIR::ConstantId::ForTemplateConstant(SemIR::ErrorInst::SingletonInstId),
SemIR::ConstantId::ForConcreteConstant(SemIR::ErrorInst::SingletonInstId),
SemIR::ErrorInst::SingletonTypeId);
type_ids_for_type_constants_.Insert(
SemIR::ConstantId::ForTemplateConstant(SemIR::TypeType::SingletonInstId),
SemIR::ConstantId::ForConcreteConstant(SemIR::TypeType::SingletonInstId),
SemIR::TypeType::SingletonTypeId);

// TODO: Remove this and add a `VerifyOnFinish` once we properly push and pop
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/control_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ auto SetBlockArgResultBeforeConstantUse(Context& context,
// Determine the constant result based on the condition value.
SemIR::ConstantId const_id = SemIR::ConstantId::NotConstant;
auto cond_const_id = context.constant_values().Get(cond_id);
if (!cond_const_id.is_template()) {
if (!cond_const_id.is_concrete()) {
// Symbolic or non-constant condition means a non-constant result.
} else if (auto literal = context.insts().TryGetAs<SemIR::BoolLiteral>(
context.constant_values().GetInstId(cond_const_id))) {
Expand Down
106 changes: 53 additions & 53 deletions toolchain/check/eval.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static auto GetInstWithConstantValue(const SemIR::File& file,
return SemIR::InstId::None;
}

// For template constants, the corresponding instruction has the desired
// For concrete constants, the corresponding instruction has the desired
// constant value.
if (!const_id.is_symbolic()) {
return file.constant_values().GetInstId(const_id);
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/member_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id,
};
// Diagnose a non-constant index prior to conversion to IntLiteral, because
// the conversion will fail if the index is not constant.
if (!context.constant_values().Get(index_inst_id).is_template()) {
if (!context.constant_values().Get(index_inst_id).is_concrete()) {
return diag_non_constant_index();
}

Expand All @@ -595,7 +595,7 @@ auto PerformTupleAccess(Context& context, SemIR::LocId loc_id,
auto index_const_id = context.constant_values().Get(index_inst_id);
if (index_const_id == SemIR::ErrorInst::SingletonConstantId) {
return SemIR::ErrorInst::SingletonInstId;
} else if (!index_const_id.is_template()) {
} else if (!index_const_id.is_concrete()) {
return diag_non_constant_index();
}

Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/subst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ class SubstConstantCallbacks final : public SubstInstCallbacks {
// Applies the given Substitutions to an instruction, in order to replace
// BindSymbolicName instructions with the value of the binding.
auto Subst(SemIR::InstId& inst_id) const -> bool override {
if (context_.constant_values().Get(inst_id).is_template()) {
// This instruction is a template constant, so can't contain any
if (context_.constant_values().Get(inst_id).is_concrete()) {
// This instruction is a concrete constant, so can't contain any
// bindings that need to be substituted.
return true;
}
Expand Down Expand Up @@ -380,7 +380,7 @@ auto SubstConstant(Context& context, SemIR::ConstantId const_id,
}

if (!const_id.is_symbolic()) {
// A template constant can't contain a reference to a symbolic binding.
// A concrete constant can't contain a reference to a symbolic binding.
return const_id;
}

Expand Down
24 changes: 12 additions & 12 deletions toolchain/check/testdata/alias/fail_bool_value.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ let a_test: bool = a;
// CHECK:STDOUT: --- fail_bool_value.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %false: bool = bool_literal false [template]
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
// CHECK:STDOUT: %false: bool = bool_literal false [concrete]
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
// CHECK:STDOUT: .Bool = %Core.Bool
// CHECK:STDOUT: import Core//prelude
// CHECK:STDOUT: import Core//prelude/...
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .Core = imports.%Core
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: .a_test = %a_test
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %false: bool = bool_literal false [template = constants.%false]
// CHECK:STDOUT: %a: <error> = bind_alias a, <error> [template = <error>]
// CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
// CHECK:STDOUT: %a: <error> = bind_alias a, <error> [concrete = <error>]
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %a_test.patt: bool = binding_pattern a_test
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc16_13.1: type = splice_block %.loc16_13.3 [template = bool] {
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %.loc16_13.2: type = value_of_initializer %bool.make_type [template = bool]
// CHECK:STDOUT: %.loc16_13.3: type = converted %bool.make_type, %.loc16_13.2 [template = bool]
// CHECK:STDOUT: %.loc16_13.1: type = splice_block %.loc16_13.3 [concrete = bool] {
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
// CHECK:STDOUT: %.loc16_13.2: type = value_of_initializer %bool.make_type [concrete = bool]
// CHECK:STDOUT: %.loc16_13.3: type = converted %bool.make_type, %.loc16_13.2 [concrete = bool]
// CHECK:STDOUT: }
// CHECK:STDOUT: %a_test: bool = bind_name a_test, <error>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %a.ref: <error> = name_ref a, file.%a [template = <error>]
// CHECK:STDOUT: %a.ref: <error> = name_ref a, file.%a [concrete = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
22 changes: 11 additions & 11 deletions toolchain/check/testdata/alias/fail_builtins.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ alias b = bool;
// CHECK:STDOUT: --- fail_builtins.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
// CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
// CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
// CHECK:STDOUT: .Int = %Core.Int
// CHECK:STDOUT: .Bool = %Core.Bool
// CHECK:STDOUT: import Core//prelude
Expand All @@ -39,16 +39,16 @@ alias b = bool;
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .Core = imports.%Core
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: .b = %b
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %a: <error> = bind_alias a, <error> [template = <error>]
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
// CHECK:STDOUT: %b: <error> = bind_alias b, <error> [template = <error>]
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: %a: <error> = bind_alias a, <error> [concrete = <error>]
// CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
// CHECK:STDOUT: %b: <error> = bind_alias b, <error> [concrete = <error>]
// CHECK:STDOUT: }
// CHECK:STDOUT:
6 changes: 3 additions & 3 deletions toolchain/check/testdata/alias/fail_control_flow.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ alias a = true or false;
// CHECK:STDOUT: --- fail_control_flow.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %true: bool = bool_literal true [template]
// CHECK:STDOUT: %true: bool = bool_literal true [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: %.loc27: bool = block_arg <unexpected instblockref inst_block5> [template = constants.%true]
// CHECK:STDOUT: %a: <error> = bind_alias a, <error> [template = <error>]
// CHECK:STDOUT: %.loc27: bool = block_arg <unexpected instblockref inst_block5> [concrete = constants.%true]
// CHECK:STDOUT: %a: <error> = bind_alias a, <error> [concrete = <error>]
// CHECK:STDOUT: }
// CHECK:STDOUT:
30 changes: 15 additions & 15 deletions toolchain/check/testdata/alias/no_prelude/alias_of_alias.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@ let d: c = {};
// CHECK:STDOUT: --- alias_of_alias.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %C: type = class_type @C [template]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
// CHECK:STDOUT: %C.val: %C = struct_value () [template]
// CHECK:STDOUT: %C: type = class_type @C [concrete]
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
// CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: .b = %b
// CHECK:STDOUT: .c = %c
// CHECK:STDOUT: .d = %d
// CHECK:STDOUT: }
// CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
// CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
// CHECK:STDOUT: %a: type = bind_alias a, %C.decl [template = constants.%C]
// CHECK:STDOUT: %a.ref: type = name_ref a, %a [template = constants.%C]
// CHECK:STDOUT: %b: type = bind_alias b, %a [template = constants.%C]
// CHECK:STDOUT: %b.ref: type = name_ref b, %b [template = constants.%C]
// CHECK:STDOUT: %c: type = bind_alias c, %b [template = constants.%C]
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
// CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [concrete = constants.%C]
// CHECK:STDOUT: %a: type = bind_alias a, %C.decl [concrete = constants.%C]
// CHECK:STDOUT: %a.ref: type = name_ref a, %a [concrete = constants.%C]
// CHECK:STDOUT: %b: type = bind_alias b, %a [concrete = constants.%C]
// CHECK:STDOUT: %b.ref: type = name_ref b, %b [concrete = constants.%C]
// CHECK:STDOUT: %c: type = bind_alias c, %b [concrete = constants.%C]
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %d.patt: %C = binding_pattern d
// CHECK:STDOUT: }
// CHECK:STDOUT: %c.ref: type = name_ref c, %c [template = constants.%C]
// CHECK:STDOUT: %c.ref: type = name_ref c, %c [concrete = constants.%C]
// CHECK:STDOUT: %.loc15_13.1: ref %C = temporary_storage
// CHECK:STDOUT: %.loc15_13.2: init %C = class_init (), %.loc15_13.1 [template = constants.%C.val]
// CHECK:STDOUT: %.loc15_13.2: init %C = class_init (), %.loc15_13.1 [concrete = constants.%C.val]
// CHECK:STDOUT: %.loc15_13.3: ref %C = temporary %.loc15_13.1, %.loc15_13.2
// CHECK:STDOUT: %.loc15_13.4: ref %C = converted @__global_init.%.loc15, %.loc15_13.3
// CHECK:STDOUT: %d: ref %C = bind_name d, %.loc15_13.4
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
Expand Down
Loading

0 comments on commit c6d35e1

Please sign in to comment.