mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 13:50:10 +01:00
This is in support of a goal of changing the blanket `destroy` impl to
use (roughly):
```
private fn CanAggregateDestroy() -> type = "type.can_aggregate_destroy";
// Handles aggregate type destruction.
impl forall [AggregateDestroyT:! CanAggregateDestroy()] AggregateDestroyT as Destroy {
fn Op[addr self: Self*]() = "type.aggregate_destroy";
}
```
That isn't done here because there's still other issues that migrating
raises. What this *does* do is add the builtin functions, and in
particular, support to `FacetTypeInfo` to make `CanAggregateDestroy`
work.
The "special requirement" approach in `FacetTypeInfo` allows us to
support restricting a blanket impl under the current approach of impls.
Maybe we'll find a cleaner approach that can work in the future, but
this fits into the current model by propagating similar to other
requirements. I'm using an enum mask because we have a number of similar
things to add (e.g. copy, move) but I'm not sure we need a full vector.
A few alternatives considered were:
- Supporting syntax more like `where .Self impls
TypeCanAggregateDestroy(.Self, SupportedInterface,
UnsupportedInterface)`. I think it'd be a little cleaner, but requires
better compile-time evaluation in order to assess the type of the call.
Right now it's expected to be a `FacetType` too early to make this work,
and I was concerned about pouring too much more time down this route.
- Providing an actual interface, in particular doing name lookup back
into `Core.` for an interface. This would've added name lookup overhead,
and the question of whether an `impl` exists.
- Generating an interface. This avoids the name lookup, but would still
raise the question of whether an `impl` should also be generated. Work
I've previously done generating interfaces for class destruction also
feels complex to both write and understand (an unfortunate issue).
- Still modeling as an `ImplsConstraint`, for example by defining a
special `InterfaceId::CanAggregateDestroy = -2` similar to what we do on
other ids. I was hesitant because of how this expands the number of
modes of `InterfaceId`, and things for consuming code to watch out for,
for what feels like a relatively niche set of use-cases that are only
interface-like.
---------
Co-authored-by: Dana Jansens <danakj@orodu.net>
231 lines
13 KiB
Plaintext
231 lines
13 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
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/primitives.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/generic/call_specific_in_class.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_specific_in_class.carbon
|
|
|
|
// Builds on `call_basic.carbon`. Checks different specific definitions are
|
|
// emitted for a generic function defined inside a class, when calling that
|
|
// generic function for an object, from a generic context.
|
|
// The specifics with a pointer type could be deduplicated here.
|
|
class C {
|
|
fn Cfn[self: Self, T:! Core.Copy](x: T) -> T {
|
|
return x;
|
|
}
|
|
}
|
|
|
|
fn G[T:! Core.Copy](x: T) -> T {
|
|
var c: C;
|
|
return c.Cfn(x);
|
|
}
|
|
|
|
fn F[T:! Core.Copy](x: T) -> T {
|
|
return G(x);
|
|
}
|
|
|
|
fn M() {
|
|
var ptr_i32 : i32*;
|
|
F(ptr_i32);
|
|
var ptr_f64 : f64*;
|
|
F(ptr_f64);
|
|
var ptr_i8 : i8*;
|
|
F(ptr_i8);
|
|
var var_i32: i32 = 0;
|
|
F(var_i32);
|
|
var var_f64: f64 = 0.0;
|
|
F(var_f64);
|
|
var c: C;
|
|
F(C);
|
|
}
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'call_specific_in_class.carbon'
|
|
// CHECK:STDOUT: source_filename = "call_specific_in_class.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: %type = type {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %ptr_i32.var = alloca ptr, align 8, !dbg !7
|
|
// CHECK:STDOUT: %ptr_f64.var = alloca ptr, align 8, !dbg !8
|
|
// CHECK:STDOUT: %ptr_i8.var = alloca ptr, align 8, !dbg !9
|
|
// CHECK:STDOUT: %var_i32.var = alloca i32, align 4, !dbg !10
|
|
// CHECK:STDOUT: %var_f64.var = alloca double, align 8, !dbg !11
|
|
// CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !12
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_i32.var), !dbg !7
|
|
// CHECK:STDOUT: %.loc34_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !13
|
|
// CHECK:STDOUT: %F.call.loc34 = call ptr @_CF.Main.a194de4a3b8dbd0c(ptr %.loc34_5), !dbg !14
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_f64.var), !dbg !8
|
|
// CHECK:STDOUT: %.loc36_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !15
|
|
// CHECK:STDOUT: %F.call.loc36 = call ptr @_CF.Main.a194de4a3b8dbd0c(ptr %.loc36_5), !dbg !16
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %ptr_i8.var), !dbg !9
|
|
// CHECK:STDOUT: %.loc38_5 = load ptr, ptr %ptr_i8.var, align 8, !dbg !17
|
|
// CHECK:STDOUT: %F.call.loc38 = call ptr @_CF.Main.a194de4a3b8dbd0c(ptr %.loc38_5), !dbg !18
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %var_i32.var), !dbg !10
|
|
// CHECK:STDOUT: store i32 0, ptr %var_i32.var, align 4, !dbg !10
|
|
// CHECK:STDOUT: %.loc40_5 = load i32, ptr %var_i32.var, align 4, !dbg !19
|
|
// CHECK:STDOUT: %F.call.loc40 = call i32 @_CF.Main.de631560529e9861(i32 %.loc40_5), !dbg !20
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %var_f64.var), !dbg !11
|
|
// CHECK:STDOUT: store double 0.000000e+00, ptr %var_f64.var, align 8, !dbg !11
|
|
// CHECK:STDOUT: %.loc42_5 = load double, ptr %var_f64.var, align 8, !dbg !21
|
|
// CHECK:STDOUT: %F.call.loc42 = call double @_CF.Main.3836ccc537683c19(double %.loc42_5), !dbg !22
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !12
|
|
// CHECK:STDOUT: %F.call.loc44 = call %type @_CF.Main.402deed6b8733082(%type zeroinitializer), !dbg !23
|
|
// CHECK:STDOUT: ret void, !dbg !24
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
|
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(ptr captures(none)) #0
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.a194de4a3b8dbd0c(ptr %x) !dbg !25 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %G.call = call ptr @_CG.Main.a194de4a3b8dbd0c(ptr %x), !dbg !26
|
|
// CHECK:STDOUT: ret ptr %G.call, !dbg !27
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.de631560529e9861(i32 %x) !dbg !28 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %G.call = call i32 @_CG.Main.de631560529e9861(i32 %x), !dbg !29
|
|
// CHECK:STDOUT: ret i32 %G.call, !dbg !30
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr double @_CF.Main.3836ccc537683c19(double %x) !dbg !31 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %G.call = call double @_CG.Main.3836ccc537683c19(double %x), !dbg !32
|
|
// CHECK:STDOUT: ret double %G.call, !dbg !33
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr %type @_CF.Main.402deed6b8733082(%type %x) !dbg !34 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %G.call = call %type @_CG.Main.402deed6b8733082(%type %x), !dbg !35
|
|
// CHECK:STDOUT: ret %type %G.call, !dbg !36
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.a194de4a3b8dbd0c(ptr %x) !dbg !37 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !38
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !38
|
|
// CHECK:STDOUT: %C.Cfn.call = call ptr @_CCfn.C.Main.a194de4a3b8dbd0c(ptr %c.var, ptr %x), !dbg !39
|
|
// CHECK:STDOUT: ret ptr %C.Cfn.call, !dbg !40
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.de631560529e9861(i32 %x) !dbg !41 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !42
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !42
|
|
// CHECK:STDOUT: %C.Cfn.call = call i32 @_CCfn.C.Main.de631560529e9861(ptr %c.var, i32 %x), !dbg !43
|
|
// CHECK:STDOUT: ret i32 %C.Cfn.call, !dbg !44
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr double @_CG.Main.3836ccc537683c19(double %x) !dbg !45 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !46
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !46
|
|
// CHECK:STDOUT: %C.Cfn.call = call double @_CCfn.C.Main.3836ccc537683c19(ptr %c.var, double %x), !dbg !47
|
|
// CHECK:STDOUT: ret double %C.Cfn.call, !dbg !48
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr %type @_CG.Main.402deed6b8733082(%type %x) !dbg !49 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: %c.var = alloca {}, align 8, !dbg !50
|
|
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(ptr %c.var), !dbg !50
|
|
// CHECK:STDOUT: %C.Cfn.call = call %type @_CCfn.C.Main.402deed6b8733082(ptr %c.var, %type %x), !dbg !51
|
|
// CHECK:STDOUT: ret %type %C.Cfn.call, !dbg !52
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr ptr @_CCfn.C.Main.a194de4a3b8dbd0c(ptr %self, ptr %x) !dbg !53 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret ptr %x, !dbg !54
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr i32 @_CCfn.C.Main.de631560529e9861(ptr %self, i32 %x) !dbg !55 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret i32 %x, !dbg !56
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr double @_CCfn.C.Main.3836ccc537683c19(ptr %self, double %x) !dbg !57 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret double %x, !dbg !58
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define linkonce_odr %type @_CCfn.C.Main.402deed6b8733082(ptr %self, %type %x) !dbg !59 {
|
|
// CHECK:STDOUT: entry:
|
|
// CHECK:STDOUT: ret %type %x, !dbg !60
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: ; uselistorder directives
|
|
// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 0, 1, 2, 3, 9, 8, 7, 6, 5, 4 }
|
|
// CHECK:STDOUT: uselistorder ptr @_CF.Main.a194de4a3b8dbd0c, { 2, 1, 0 }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
|
|
// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
|
|
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
|
|
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
|
|
// CHECK:STDOUT: !3 = !DIFile(filename: "call_specific_in_class.carbon", directory: "")
|
|
// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 32, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
|
|
// CHECK:STDOUT: !6 = !{}
|
|
// CHECK:STDOUT: !7 = !DILocation(line: 33, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !8 = !DILocation(line: 35, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !9 = !DILocation(line: 37, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !10 = !DILocation(line: 39, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !11 = !DILocation(line: 41, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !12 = !DILocation(line: 43, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !13 = !DILocation(line: 34, column: 5, scope: !4)
|
|
// CHECK:STDOUT: !14 = !DILocation(line: 34, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !15 = !DILocation(line: 36, column: 5, scope: !4)
|
|
// CHECK:STDOUT: !16 = !DILocation(line: 36, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !17 = !DILocation(line: 38, column: 5, scope: !4)
|
|
// CHECK:STDOUT: !18 = !DILocation(line: 38, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !19 = !DILocation(line: 40, column: 5, scope: !4)
|
|
// CHECK:STDOUT: !20 = !DILocation(line: 40, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !21 = !DILocation(line: 42, column: 5, scope: !4)
|
|
// CHECK:STDOUT: !22 = !DILocation(line: 42, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !23 = !DILocation(line: 44, column: 3, scope: !4)
|
|
// CHECK:STDOUT: !24 = !DILocation(line: 32, column: 1, scope: !4)
|
|
// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.a194de4a3b8dbd0c", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !26 = !DILocation(line: 29, column: 10, scope: !25)
|
|
// CHECK:STDOUT: !27 = !DILocation(line: 29, column: 3, scope: !25)
|
|
// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.de631560529e9861", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !29 = !DILocation(line: 29, column: 10, scope: !28)
|
|
// CHECK:STDOUT: !30 = !DILocation(line: 29, column: 3, scope: !28)
|
|
// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.3836ccc537683c19", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !32 = !DILocation(line: 29, column: 10, scope: !31)
|
|
// CHECK:STDOUT: !33 = !DILocation(line: 29, column: 3, scope: !31)
|
|
// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.402deed6b8733082", scope: null, file: !3, line: 28, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !35 = !DILocation(line: 29, column: 10, scope: !34)
|
|
// CHECK:STDOUT: !36 = !DILocation(line: 29, column: 3, scope: !34)
|
|
// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.a194de4a3b8dbd0c", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !38 = !DILocation(line: 24, column: 3, scope: !37)
|
|
// CHECK:STDOUT: !39 = !DILocation(line: 25, column: 10, scope: !37)
|
|
// CHECK:STDOUT: !40 = !DILocation(line: 25, column: 3, scope: !37)
|
|
// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.de631560529e9861", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !42 = !DILocation(line: 24, column: 3, scope: !41)
|
|
// CHECK:STDOUT: !43 = !DILocation(line: 25, column: 10, scope: !41)
|
|
// CHECK:STDOUT: !44 = !DILocation(line: 25, column: 3, scope: !41)
|
|
// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.3836ccc537683c19", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !46 = !DILocation(line: 24, column: 3, scope: !45)
|
|
// CHECK:STDOUT: !47 = !DILocation(line: 25, column: 10, scope: !45)
|
|
// CHECK:STDOUT: !48 = !DILocation(line: 25, column: 3, scope: !45)
|
|
// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.402deed6b8733082", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !50 = !DILocation(line: 24, column: 3, scope: !49)
|
|
// CHECK:STDOUT: !51 = !DILocation(line: 25, column: 10, scope: !49)
|
|
// CHECK:STDOUT: !52 = !DILocation(line: 25, column: 3, scope: !49)
|
|
// CHECK:STDOUT: !53 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.a194de4a3b8dbd0c", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !54 = !DILocation(line: 19, column: 5, scope: !53)
|
|
// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.de631560529e9861", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !56 = !DILocation(line: 19, column: 5, scope: !55)
|
|
// CHECK:STDOUT: !57 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.3836ccc537683c19", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !58 = !DILocation(line: 19, column: 5, scope: !57)
|
|
// CHECK:STDOUT: !59 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.402deed6b8733082", scope: null, file: !3, line: 18, type: !5, spFlags: DISPFlagDefinition, unit: !2)
|
|
// CHECK:STDOUT: !60 = !DILocation(line: 19, column: 5, scope: !59)
|