mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 17:24:57 +01:00
Add a general substitution mechanism to support substituting symbolic bindings with their values throughout symbolic constants and, more specifically, types. This is done by decomposing the constant instruction into its operands, substituting into the operands, and then rebuilding the constant value by invoking the constant evaluator. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
43 lines
933 B
Plaintext
43 lines
933 B
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
interface I {
|
|
fn F() -> i32;
|
|
}
|
|
|
|
class A {
|
|
extend impl as I {
|
|
fn F() -> i32 {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn TypeAccess() -> i32 {
|
|
return A.F();
|
|
}
|
|
|
|
fn InstanceAccess(a: A) -> i32 {
|
|
return a.F();
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'extend_impl.carbon'
|
|
// CHECK:STDOUT: source_filename = "extend_impl.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @F() {
|
|
// CHECK:STDOUT: ret i32 0
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @TypeAccess() {
|
|
// CHECK:STDOUT: %F = call i32 @F()
|
|
// CHECK:STDOUT: ret i32 %F
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @InstanceAccess(ptr %a) {
|
|
// CHECK:STDOUT: %F = call i32 @F()
|
|
// CHECK:STDOUT: ret i32 %F
|
|
// CHECK:STDOUT: }
|