Skip to content

Ensure calls to getters have a source location. #66260

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
Jun 1, 2023
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
5 changes: 4 additions & 1 deletion include/swift/SIL/SILLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class SILLocation {
/// Marks the location as coming from auto-generated body.
void markAutoGenerated() { kindAndFlags.fields.autoGenerated = true; }

/// Marks the location as not bein auto-generated.
/// Marks the location as not being auto-generated.
/// FIXME: This functionality is only used to work around bugs and should be
/// removed.
void markNonAutoGenerated() { kindAndFlags.fields.autoGenerated = false; }
Expand All @@ -364,6 +364,9 @@ class SILLocation {
/// and these two properties should be merged.
bool isImplicit() const { return kindAndFlags.fields.implicit; }

/// Mark this location as not being implicit.
void markExplicit() { kindAndFlags.fields.implicit = false; }

/// Returns false if the location should be represented in debuginfo.
bool isHiddenFromDebugInfo() const {
return (isAutoGenerated() || isImplicit()) && !hasASTNodeForDebugging();
Expand Down
5 changes: 5 additions & 0 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6635,6 +6635,11 @@ RValue SILGenFunction::emitGetAccessor(
// Scope any further writeback just within this operation.
FormalEvaluationScope writebackScope(*this);

// Calls to getters are implicit because the compiler inserts them on a
// property access, but the location is useful in backtraces so it should be
// preserved.
loc.markExplicit();

Callee getter = emitSpecializedAccessorFunctionRef(
*this, loc, get, substitutions, selfValue, isSuper, isDirectUse,
isOnSelfParameter);
Expand Down
10 changes: 10 additions & 0 deletions test/DebugInfo/lazy-getter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend %s -Onone -emit-ir -g -o - -parse-as-library -module-name a | %FileCheck %s
func use<T>(_ t : T) {}
public func f() -> (() -> ()) {
lazy var i : Int = 0
return {
// CHECK: call {{.*}} @"$s1a1fyycyF1iL_Sivg"({{.*}}), !dbg ![[GETTER_LOC:[0-9]+]]
// CHECK: ![[GETTER_LOC]] = !DILocation(line: [[@LINE+1]], column: 11
use(i)
}
}