mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 11:12:41 +00:00
This removes the builtin FunctionType, replacing it with a FunctionType instruction. The constant for a FunctionDecl is now a StructValue with type of FunctionType. Note this means a function declaration produces _both_ a type, and a value of the type. This has some consequences in terms of circularity, and makes the importing of function declarations a little more complex. It'll get particularly peculiar for imports because of the behavior of the reference, but that's a known issue due to other things such as `alias`. The impact will hopefully be contained to ResolvePrevInstForMerge (and ImportRefs). To note a small formatting change in diagnostics: ``` - // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated <function> in Interface>` is not callable. + // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated F in Interface>` is not callable. - // CHECK:STDERR: fail_todo_facet_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated <function> in Interface>` is not callable. + // CHECK:STDERR: fail_todo_facet_lookup.carbon:[[@LINE+4]]:3: ERROR: Value of type `<associated F in Interface>` is not callable. ``` --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
86 lines
3.4 KiB
Plaintext
86 lines
3.4 KiB
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
|
|
|
|
namespace NS;
|
|
|
|
alias ns = NS;
|
|
|
|
fn NS.A() -> i32 { return 0; }
|
|
|
|
fn B() -> i32 { return ns.A(); }
|
|
|
|
alias C = NS.A;
|
|
|
|
fn D() -> i32 { return C(); }
|
|
|
|
// CHECK:STDOUT: --- alias.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %A: type = fn_type @A [template]
|
|
// CHECK:STDOUT: %.1: type = tuple_type () [template]
|
|
// CHECK:STDOUT: %struct.1: A = struct_value () [template]
|
|
// CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
|
|
// CHECK:STDOUT: %B: type = fn_type @B [template]
|
|
// CHECK:STDOUT: %struct.2: B = struct_value () [template]
|
|
// CHECK:STDOUT: %D: type = fn_type @D [template]
|
|
// CHECK:STDOUT: %struct.3: D = struct_value () [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Core = %Core
|
|
// CHECK:STDOUT: .NS = %NS
|
|
// CHECK:STDOUT: .ns = %ns
|
|
// CHECK:STDOUT: .B = %B.decl
|
|
// CHECK:STDOUT: .C = %C
|
|
// CHECK:STDOUT: .D = %D.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: %NS: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .A = %A.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %NS.ref.loc9: <namespace> = name_ref NS, %NS [template = %NS]
|
|
// CHECK:STDOUT: %ns: <namespace> = bind_alias ns, %NS [template = %NS]
|
|
// CHECK:STDOUT: %A.decl: A = fn_decl @A [template = constants.%struct.1] {
|
|
// CHECK:STDOUT: @A.%return: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %B.decl: B = fn_decl @B [template = constants.%struct.2] {
|
|
// CHECK:STDOUT: @B.%return: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %NS.ref.loc15: <namespace> = name_ref NS, %NS [template = %NS]
|
|
// CHECK:STDOUT: %A.ref: A = name_ref A, %A.decl [template = constants.%struct.1]
|
|
// CHECK:STDOUT: %C: A = bind_alias C, %A.decl [template = constants.%struct.1]
|
|
// CHECK:STDOUT: %D.decl: D = fn_decl @D [template = constants.%struct.3] {
|
|
// CHECK:STDOUT: @D.%return: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @A() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc11: i32 = int_literal 0 [template = constants.%.2]
|
|
// CHECK:STDOUT: return %.loc11
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @B() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %ns.ref: <namespace> = name_ref ns, file.%ns [template = file.%NS]
|
|
// CHECK:STDOUT: %A.ref: A = name_ref A, file.%A.decl [template = constants.%struct.1]
|
|
// CHECK:STDOUT: %A.call: init i32 = call %A.ref()
|
|
// CHECK:STDOUT: %.loc13_30.1: i32 = value_of_initializer %A.call
|
|
// CHECK:STDOUT: %.loc13_30.2: i32 = converted %A.call, %.loc13_30.1
|
|
// CHECK:STDOUT: return %.loc13_30.2
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @D() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %C.ref: A = name_ref C, file.%C [template = constants.%struct.1]
|
|
// CHECK:STDOUT: %A.call: init i32 = call %C.ref()
|
|
// CHECK:STDOUT: %.loc17_27.1: i32 = value_of_initializer %A.call
|
|
// CHECK:STDOUT: %.loc17_27.2: i32 = converted %A.call, %.loc17_27.1
|
|
// CHECK:STDOUT: return %.loc17_27.2
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|