Skip to content

[DebugInfo] Stop handling InOut types, they'll be gone soon. #21095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
SILType type, DeclContext *DeclCtx,
GenericEnvironment *GE) {
auto RealType = type.getASTType();
if (type.isAddress())
RealType = CanInOutType::get(RealType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worries me. Are you representing the address-ness some other way now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code was unused.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I didn't write this, so I guess @adrian-prantl is in a better position to judge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check whether LLDB attaches any semantics to InOut or if it is pure sugar. If it's the latter then this is safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests in LLDB that exercise inout types?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put a regular Int field in the struct too, then, and make sure you can print that. That's easier than checking the weak reference, though of course that should also be correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple this is what I'm seeing.

(lldb) target create "./run"
b -l Current executable set to './run' (x86_64).
(lldb) b -l 8
Breakpoint 1: where = run`run.test(run.X) -> () + 50 at run.swift:8:9, address = 0x0000000100001742
(lldb) r
Process 16896 launched: '/Users/davide/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/run' (x86_64)
Process 16896 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100001742 run`test(x=run.X @ 0x00007ffeefbff9b0) at run.swift:8:9
   5   	
   6   	func test(_ x: X) {
   7   	  var y = x
-> 8   	  print(y)
   9   	}
   10  	
   11  	test(X(foo: 23 as AnyObject, patatino: 23))
Target 0: (run) stopped.
(lldb) frame var y
(run.X) y = {
  foo = nil
  patatino = 23
}
struct X {
  weak var foo: AnyObject?
  var patatino : Int
}

func test(_ x: X) {
  var y = x
  print(y)
}

test(X(foo: 23 as AnyObject, patatino: 23))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like correct behavior, although it would be a better test if you had a class instance that was kept alive until after you were done calling test. If that works with and without your change, then I think it's all good.

Copy link
Member Author

@dcci dcci Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple Looks like that case is broken with and without my change

(lldb) frame var y
(run.X) y = {
  foo = (instance = 0x0000000100a00002) {
    instance = 0x0000000100a00002
  }
  patatino = 23
}
class Tinky {
  var x : Int
  init(_ x : Int) {
    self.x = x
  }
}

struct X {
  weak var foo: AnyObject?
  var patatino : Int
}

func test(_ x: X) {
  var y = x
  print(y)
}

var a = Tinky(23)
test(X(foo: a, patatino: 23))
print(a)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple given it seems unrelated, I'll open a rdar for this and look at it next.

auto DbgTy = DebugTypeInfo::getFromTypeInfo(DeclCtx, GE, RealType,
IGM.getTypeInfo(type));
Parameters.push_back(getOrCreateType(DbgTy));
Expand Down Expand Up @@ -1192,22 +1190,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
AlignInBits, Flags, MangledName);
}

case TypeKind::InOut: {
// This is an inout type. Naturally we would be emitting them as
// DW_TAG_reference_type types, but LLDB can deal better with
// pointer-sized struct that has the appropriate mangled name.
auto ObjectTy = BaseTy->castTo<InOutType>()->getObjectType();
auto Name = MangledName;
if (auto *Decl = ObjectTy->getAnyNominal())
Name = Decl->getName().str();
if (Opts.DebugInfoLevel > IRGenDebugInfoLevel::ASTTypes) {
auto DT = getOrCreateDesugaredType(ObjectTy, DbgTy);
return createPointerSizedStruct(Scope, Name, DT, File, 0, Flags,
MangledName);
} else
return createOpaqueStruct(Scope, Name, File, 0, SizeInBits, AlignInBits,
Flags, MangledName);
}
case TypeKind::InOut:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the user-facing inout type disappear, too? Or do we still need to mangle inout types so we can preserve the sugar in LLDB (i.e.: should p result show (inout Int)result ?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrian-prantl I had a quick discussion with @slavapestov yesterday and he suggested we shouldn't print anything at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it's been pointed out that InOut types are not real types but InOut is more a property of function parameters so if we want to model we should model it as such.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it is not particularly useful information.

break;

case TypeKind::Archetype: {
auto *Archetype = BaseTy->castTo<ArchetypeType>();
Expand Down Expand Up @@ -1384,10 +1368,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
case TypeKind::SILBlockStorage: // Not supported at all.
case TypeKind::SILBox:
return false;
case TypeKind::InOut: {
auto *ObjectTy = Ty->castTo<InOutType>()->getObjectType().getPointer();
return canMangle(ObjectTy);
}
default:
return true;
}
Expand Down
11 changes: 3 additions & 8 deletions test/DebugInfo/archetypes2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ func markUsed<T>(_ t: T) {}

class C<A> {
// CHECK: ![[A:.*]] = !DICompositeType(tag: DW_TAG_structure_type,{{.*}}identifier: "$sxD"
// CHECK: !DILocalVariable(name: "x", arg: 1,
// CHECK-SAME: line: [[@LINE+7]],
// CHECK-SAME: type: ![[A]]
// CHECK: !DILocalVariable(name: "y", arg: 2,
// CHECK-SAME: line: [[@LINE+4]],
// CHECK-SAME: type: ![[B:[0-9]+]]
// CHECK: ![[B]] = !DICompositeType(tag: DW_TAG_structure_type,
// CHECK-SAME: identifier: "$sqd__D"
// CHECK: ![[B:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type,{{.*}}identifier: "$sqd__D")
// CHECK: !DILocalVariable(name: "x", arg: 1,{{.*}}line: [[@LINE+2]],{{.*}}type: ![[A]]
// CHECK: !DILocalVariable(name: "y", arg: 2,{{.*}}line: [[@LINE+1]],{{.*}}type: ![[B]])
func foo<B>(_ x: A, y :B) {
markUsed("hello world")
}
Expand Down
1 change: 0 additions & 1 deletion test/DebugInfo/enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func foo<T>(_ x : Rose<T>) -> Rose<T> { return x }
// DWARF: !DICompositeType({{.*}}name: "Tuple", {{.*}}elements: ![[ELTS:[0-9]+]],
// DWARF-SAME: {{.*}}identifier: "$s4enum5TupleOyxG{{z?}}D")
public enum Tuple<P> {
// DWARF: !DICompositeType({{.*}}name: "Tuple",{{.*}}identifier: "$s4enum5TupleOyxGD")
case C(P, () -> Tuple)
}

Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/generic_arg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ func foo<T>(_ x: T) -> () {
// CHECK-SAME: metadata ![[X1:.*]], metadata !DIExpression(DW_OP_deref))
// CHECK: store %swift.type* %T, %swift.type** %[[T]],
// CHECK: store %swift.opaque* %0, %swift.opaque** %[[X]],
// CHECK: ![[TY2:.*]] = !DICompositeType({{.*}}identifier: "$sxD")
// CHECK: ![[T1]] = !DILocalVariable(name: "$\CF\84_0_0",
// CHECK-SAME: flags: DIFlagArtificial)
// CHECK: ![[X1]] = !DILocalVariable(name: "x", arg: 1,
// CHECK-SAME: line: 3, type: ![[TY:.*]])
// CHECK: ![[TY]] = !DICompositeType({{.*}}identifier: "$sxD")
// CHECK-SAME: line: 3, type: ![[TY2]])
_blackHole(x)
}

Expand Down
7 changes: 3 additions & 4 deletions test/DebugInfo/generic_arg5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public func foo<Type>(_ values : [S<Type>])
// CHECK-SAME: metadata ![[ARG:[0-9]+]],
// CHECK-SAME: metadata !DIExpression(DW_OP_deref))
// CHECK: store %[[TY]]* %1, %[[TY]]** %[[ALLOCA]], align
// CHECK: ![[TYP:.*]] = !DICompositeType({{.*}}, identifier: "$s12generic_arg51SVyxGD")
// The argument is a by-ref struct and thus needs to be dereferenced.
// CHECK: ![[ARG]] = !DILocalVariable(name: "arg", arg: 1,
// CHECK-SAME: line: [[@LINE+4]],
// CHECK-SAME: type: ![[TY:.*]])
// CHECK: ![[TY]] = !DICompositeType(
// CHECK-SAME: identifier: "$s12generic_arg51SVyxGD")
// CHECK-SAME: line: [[@LINE+2]],
// CHECK-SAME: type: ![[TYP]])
let _ = values.flatMap { arg in
return .some(arg)
}
Expand Down
5 changes: 1 addition & 4 deletions test/DebugInfo/generic_args.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ class AnotherClass : AProtocol {
func f() -> String { return "B" }
}

// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "$sq_D",{{.*}} elements: ![[PROTOS:[0-9]+]]
// CHECK-DAG: ![[PROTOS]] = !{![[INHERIT:.*]]}
// CHECK-DAG: ![[INHERIT]] = !DIDerivedType(tag: DW_TAG_inheritance,{{.*}} baseType: ![[PROTOCOL:[0-9]+]]
// CHECK-DAG: ![[PROTOCOL]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s12generic_args9AProtocol_pmD",
// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "$sq_D",{{.*}}
// CHECK-DAG: !DILocalVariable(name: "x", arg: 1,{{.*}} type: ![[T:.*]])
// CHECK-DAG: ![[T]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$sxD"
// CHECK-DAG: !DILocalVariable(name: "y", arg: 2,{{.*}} type: ![[Q:.*]])
Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/inlined-generics-basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public class C<R> {
// IR: ![[BOOL:[0-9]+]] = !DICompositeType({{.*}}name: "Bool"
// IR: ![[INT:[0-9]+]] = !DICompositeType({{.*}}name: "Int"
// IR: ![[TAU_0_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sxD",
// IR: ![[TAU_1_0:[0-9]+]] = {{.*}}DW_TAG_structure_type, name: "$sqd__D",
// IR: ![[MD_1_0]] = !DILocalVariable(name: "$\CF\84_1_0"
// IR: ![[S]] = !DILocalVariable(name: "s", {{.*}} type: ![[TAU_1_0:[0-9]+]]
// IR: ![[TAU_1_0]] = {{.*}}DW_TAG_structure_type, name: "$sqd__D",
// IR: ![[S]] = !DILocalVariable(name: "s", {{.*}} type: ![[TAU_1_0]]
// IR: ![[GS_T]] = !DILocalVariable(name: "t", {{.*}} scope: ![[SP_GS_T:[0-9]+]], {{.*}} type: ![[TAU_1_0]])
// IR: ![[SP_GS_T]] = {{.*}}linkageName: "$s1A1gyyxlFqd___Ti5"
// IR: ![[GS_U]] = !DILocalVariable(name: "u", {{.*}} scope: ![[SP_GS_U:[0-9]+]], {{.*}} type: ![[TAU_1_0]])
Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/protocolarg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public protocol IGiveOutInts {
public func printSomeNumbers(_ gen: IGiveOutInts) {
var gen = gen
// FIXME: Should be DW_TAG_interface_type
// CHECK: ![[PT:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "IGiveOutInts"
// CHECK: ![[ARG]] = !DILocalVariable(name: "gen", arg: 1,
// CHECK-SAME: line: [[@LINE-4]], type: ![[PT:[0-9]+]]
// CHECK: ![[PT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "IGiveOutInts"
// CHECK-SAME: line: [[@LINE-5]], type: ![[PT]]
// CHECK: ![[VAR]] = !DILocalVariable(name: "gen", {{.*}} line: [[@LINE-5]]
markUsed(gen.callMe())
use(&gen)
Expand Down
3 changes: 0 additions & 3 deletions test/DebugInfo/struct_resilience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ func f() {
}
f()

// CHECK: ![[TY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Size",
// CHECK: ![[TY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Size",

// CHECK: ![[V1]] = !DILocalVariable(name: "s1", {{.*}}type: ![[TY]])

// CHECK-LLDB: ![[TY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Size",
// CHECK-LLDB: ![[TY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Size",
// CHECK-LLDB: ![[V1]] = !DILocalVariable(name: "s1", {{.*}}type: ![[TY]])