Commit Graph

1220 Commits

Author SHA1 Message Date
Slava Pestov
41ccedc999 AST: Fix opaque type mangling used by type reconstruction
Make sure we mangle opaque types using the same settings as the
debugger mangling (with OptimizeProtocolNames = false) to ensure
that we can reconstruct those names again.
2020-04-10 15:05:54 -04:00
Slava Pestov
3e4b95f234 ASTMangler: Fix substitution round-tripping in the DWARF mangler
When mangling sugared types for DWARF debug info, we would
occassionally mix generic parameter types from different
generic environments. Since the mangling for a generic
parameter type only recorded the depth and the index, even
for distinct sugared forms, the remangler would produce a
more 'compact' mangling, by folding together generic parameters
that have the same depth/index, but distinct sugarings in the
AST.

Prevent this from happening by desugaring DWARF types the
correct amount, substituting away generic parameters while
preserving everything else.

Also, re-enable the round-trip verification with the remangler.

Fixes <rdar://problem/59496022>, <https://bugs.swift.org/browse/SR-12204>.
2020-04-06 18:19:57 -04:00
Slava Pestov
c543838854 Sema: Rewrite partial applications into closures
When a method is called with fewer than two parameter lists,
transform it into a fully-applied call by wrapping it in a
closure.

Eg,

Foo.bar => { self in { args... self.bar(args...) } }
foo.bar => { self in { args... self.bar(args...) } }(self)

super.bar => { args... in super.bar(args...) }

With this change, SILGen only ever sees fully-applied calls,
which will allow ripping out some code.

This new way of doing curry thunks fixes a long-standing bug
where unbound references to protocol methods did not work.

This is because such a reference must open the existential
*inside* the closure, after 'self' has been applied, whereas
the old SILGen implementation of curry thunks really wanted
the type of the method reference to match the opened type of
the method.

A follow-up cleanup will remove the SILGen curry thunk
implementation.

Fixes rdar://21289579 and https://bugs.swift.org/browse/SR-75.
2020-03-18 09:29:22 -04:00
Adrian Prantl
56309f6b49 Debug Info: Store the SDK in the DICompileUnit.
This an intermediate step for PR44213
(https://bugs.llvm.org/show_bug.cgi?id=44213).

This stores the SDK *name* in the debug info, to make it possible to
`-fdebug-prefix-map`-replace the sysroot with a recognizable string and allowing
the debugger to find a fitting SDK relative to itself, not the machine the
executable was compiled on.

rdar://problem/51645582
2020-03-13 13:25:39 -07:00
Joe Groff
19770e6471 IRGen: Keep substituted function types out of debug info for now. 2020-02-24 12:14:21 -08:00
Erik Eckstein
56ecb8fc9b Enable better runtime failure messages
The implementation was done quite a while ago.
Now, that we have support in lldb (https://github.com/apple/llvm-project/pull/773), we can enable it by default in the compiler.

LLDB now shows the runtime failure reason, for example:

* thread #1, queue = 'com.apple.main-thread', stop reason = Swift runtime failure: arithmetic overflow
    frame #1: 0x0000000100000f0d a.out`testit(a=127) at trap_message.swift:4
   1
   2   	@inline(never)
   3   	func testit(_ a: Int8) -> Int8 {
-> 4   	  return a + 1
   5   	}
   6

For details, see https://github.com/apple/swift/pull/25978

rdar://problem/51278690
2020-02-18 12:03:57 +01:00
Erik Eckstein
85789367a3 SILOptimizer: restructure the apply(partial_apply) peephole and the dead partial_apply elimination optimizations
Changes:

* Allow optimizing partial_apply capturing opened existential: we didn't do this originally because it was complicated to insert the required alloc/dealloc_stack instructions at the right places. Now we have the StackNesting utility, which makes this easier.

* Support indirect-in parameters. Not super important, but why not? It's also easy to do with the StackNesting utility.

* Share code between dead closure elimination and the apply(partial_apply) optimization. It's a bit of refactoring and allowed to eliminate some code which is not used anymore.

* Fix an ownership problem: We inserted copies of partial_apply arguments _after_ the partial_apply (which consumes the arguments).

* When replacing an apply(partial_apply) -> apply and the partial_apply becomes dead, avoid inserting copies of the arguments twice.

These changes don't have any immediate effect on our current benchmarks, but will allow eliminating curry thunks for existentials.
2020-02-11 12:48:39 +01:00
swift-ci
227485bf02 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-10 07:14:14 -08:00
Mishal Shah
f53b1a7ba1 Revert "Emit debug info for generic type aliases. …" 2020-02-09 21:38:45 -08:00
swift-ci
8b58328bc6 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-07 17:04:27 -08:00
Adrian Prantl
e932580c8e Emit debug info for generic type aliases.
Before comparing the potential sugared type for equality is needs to be mapped
into the context to resolve generic type parameters to primary archetypes.

<rdar://problem/59238327>
2020-02-07 14:06:08 -08:00
swift-ci
3b22614896 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 20:23:34 -08:00
Adrian Prantl
2113df4a75 Improve testcase
This patch makes BoundGenericEnum more robust by splitting it into three
separately executed FileCheck invocation. It further corrects an error in case
(1) were the wrong variable was being checked. Finally, by enabling
optimizations, it is easier to follow why the generic arguments have different
sizes.
2020-02-06 17:27:41 -08:00
swift-ci
e6e06c8752 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-29 09:23:16 -08:00
adrian-prantl
9676625b96 Merge pull request #29522 from adrian-prantl/test-update
Compile libraries in testcases with -parse-as-library (NFC)
2020-01-29 09:12:46 -08:00
Adrian Prantl
37e403db78 Compile libraries in testcases with -parse-as-library (NFC)
This is in preparation to a change in serialization of global variables where
this detail will matter.
2020-01-28 17:37:52 -08:00
swift-ci
70fa9f3288 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-28 16:23:20 -08:00
Med Ismail Bennani
bf41881bcd Move swift runtime failure from linkage name to function name
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-01-28 22:56:05 +01:00
Adrian Prantl
8ed230fb73 Update testcase for upstream LLVM changes. 2020-01-14 11:33:31 -08:00
Saleem Abdulrasool
440b39a263 test: adjust DebugInfo tests for new LLVM update
The filename on Windows now uses `\\` rather than `\\5C` for the path
separator.  Adjust the tests accordingly.
2020-01-13 15:13:38 -08:00
swift-ci
fc308b648d Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 13:44:18 -08:00
Slava Pestov
3b9014dc9a Merge pull request #28324 from zoecarver/optimize/dead-global-vars
Optimize dead private global variables
2020-01-13 16:41:21 -05:00
swift-ci
9092fb591b Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-11 11:03:34 -08:00
Arnold Schwaighofer
b36729a2be Fix test/DebugInfo/shadow_copies.swift 2020-01-11 10:28:02 -08:00
swift-ci
bc5eca8388 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 16:43:42 -08:00
Vedant Kumar
a83bfabc8b [DebugInfo] Stop relying on asm gadgets to extend variable ranges (#29029)
The 'fake use' asm gadget does not always keep variables alive. E.g., in
rdar://57754659, llvm was unable to preserve two local variables despite
the use of these gadgets. These variables were backed by a LoadInst and
an ExtractValueInst respectively. Instead of emitting shadow copies for
just those kinds of instructions, use shadow copies exclusively. This
may cause more variables to appear in the debugger window before they
are initialized, but should result in fewer variables being dropped.

rdar://57754659
2020-01-10 16:31:51 -08:00
Adrian Prantl
06906ab6b9 Adapt to upstream LLVM changes. 2020-01-10 09:58:57 -08:00
zoecarver
c999cd2af3 Fix inlinescopes test 2019-12-12 13:07:47 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Adrian Prantl
bdc1eec983 Use the same alignment for writing and readin .swift_ast section contents.
This fixes a bug that made it impossible to read any subsequent Swift modules
out of a .swift_ast section a previous section had a size divisible by 4.

rdar://problem/57110020
2019-12-04 14:39:12 -08:00
Jonas Devlieghere
a7fc85aedb [test] XFAIL local-vars.swift.gyb on Windows 2019-12-03 18:39:52 -08:00
Jonas Devlieghere
7e3ba68d2d [test] Re-enable local-vars.swift.gyb
This test was disabled because of a bug in dwarfdump's verifier. The bug
was fixed which means this test should be enabled again.
2019-12-02 16:38:03 -08:00
swift_jenkins
f919e12436 Merge remote-tracking branch 'origin/master' into master-next 2019-11-17 15:40:26 -08:00
Michael Gottesman
269762eee3 [ownership] Enable ownership lowering /after/ the diagnostic passes.
I also updated the last group of straggling tests.
2019-11-17 11:34:43 -08:00
swift_jenkins
b9f998ffa4 Merge remote-tracking branch 'origin/master' into master-next 2019-11-15 15:56:48 -08:00
Andrew Trick
38c29e231e Generalize and fix SinkAddressProjections.
Fixes a potential real bug in the case that SinkAddressProjections moves
projections without notifying SimplifyCFG of the change. This could
fail to update Analyses (probably won't break anything in practice).

Introduce SILInstruction::isPure. Among other things, this can tell
you if it's safe to duplicate instructions at their
uses. SinkAddressProjections should check this before sinking uses. I
couldn't find a way to expose this as a real bug, but it is a
theoretical bug.

Add the SinkAddressProjections functionality to the BasicBlockCloner
utility. Enable address projection sinking for all BasicBlockCloner
clients (the four different kinds of jump-threading that use it). This
brings the compiler much closer to banning all address phis.

The "bugs" were originally introduced a week ago here:

commit f22371bf0b (fork/fix-address-phi, fix-address-phi)
Author: Andrew Trick <atrick@apple.com>
Date:   Tue Sep 17 16:45:51 2019

    Add SIL SinkAddressProjections utility to avoid address phis.

    Enable this utility during jump-threading in SimplifyCFG.

    Ultimately, the SIL verifier should prevent all address-phis and we'll
    need to use this utility in a few more places.

    Fixes <rdar://problem/55320867> SIL verification failed: Unknown
    formal access pattern: storage
2019-11-14 16:11:00 -08:00
swift-ci
6996cae94c Merge remote-tracking branch 'origin/master' into master-next 2019-11-05 08:49:43 -08:00
swift-ci
d162cc1258 Merge remote-tracking branch 'origin/master' into master-next 2019-11-04 13:50:06 -08:00
Adrian Prantl
8e9b02839b Debug Info: Avoid type uniquing clashes for bound generic structs.
This patch changes the DWARF representation of bound generic struct to a nested
struct where the (sized) outer struct is anonymous and thus distinct and the
inner struct in uniqued and sizeless.

This is anologous the the previous commit that did the same thing for bound
generic enums.

rdar://problem/56521648
2019-11-04 13:36:49 -08:00
Adrian Prantl
e881168d5e Debug Info: Avoid type uniquing clashes for bound generic enums.
This patch changes the DWARF representation of bound generic enums to a nested
struct where the (sized) outer struct is anonymous and thus distinct and the
inner struct in uniqued and sizeless.

BoundGenericEnums may have different sizes depending on what they are bound to,
but still share a mangled name.

rdar://problem/56521648
2019-11-04 08:22:00 -08:00
swift-ci
c468d3fd32 Merge remote-tracking branch 'origin/master' into master-next 2019-11-01 10:29:36 -07:00
Adrian Prantl
ed8294247b Add a hidden option to disable debugger shadow copies.
This option is useful to debug the compiler itself, to simulate debug info as it
would be generated when producing optimized code, but without the unpredictable
output of an optimizing debugger.
2019-10-31 17:35:16 -07:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Varun Gandhi
68a68cb564 Merge pull request #27635 from varungandhi-apple/vg-robustify-module-trace-emission
Make module trace emission more robust.
2019-10-15 20:45:04 -07:00
Varun Gandhi
903add2c3f [Frontend] Make the module trace emission more robust.
✔ More informative error messages in case of crashes.
✔ Handling and documenting different cases.
✔ Test cases for different cases.
✔ Make SDKDependencies.swift pass again.
2019-10-15 15:44:26 -07:00
Nathan Hawes
181c1fdb13 [test] XFAIL DebugInfo/self.swift when assertions are disabled
Failing on CI here: https://ci.swift.org/job/oss-swift_tools-R_stdlib-RD_test-simulator/
2019-10-15 11:39:07 -07:00
swift-ci
7ea2853836 Merge remote-tracking branch 'origin/master' into master-next 2019-10-12 14:10:25 -07:00
Saleem Abdulrasool
ff4f234333 DebugInfo: loosen producer pattern
Be more accepting of vendor patterns.  Any name can be added by
configuration, so loosen the test.
2019-10-11 22:06:53 -07:00
Mishal Shah
6b33f225eb Merge branch 'master' into master-next 2019-10-01 13:10:07 -07:00
adrian-prantl
00c64e7959 Merge pull request #27345 from adrian-prantl/16042546
Debug Info: Encode let-bindings using DW_TAG_const_type.
2019-09-27 14:39:56 -07:00