mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 15:44:53 +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>
36 lines
830 B
Plaintext
36 lines
830 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
|
|
|
|
class A;
|
|
|
|
interface GetSelf {
|
|
fn Get[addr self: Self*]() -> Self*;
|
|
}
|
|
|
|
class A {
|
|
extend impl as GetSelf {
|
|
fn Get[addr self: Self*]() -> Self* {
|
|
return self;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn Call(a: A*) -> A* {
|
|
return (*a).Get();
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'instance_method.carbon'
|
|
// CHECK:STDOUT: source_filename = "instance_method.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define ptr @Get(ptr %self) {
|
|
// CHECK:STDOUT: ret ptr %self
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define ptr @Call(ptr %a) {
|
|
// CHECK:STDOUT: %Get = call ptr @Get(ptr %a)
|
|
// CHECK:STDOUT: ret ptr %Get
|
|
// CHECK:STDOUT: }
|