Commit Graph

1613 Commits

Author SHA1 Message Date
Joe Groff
6547c69b33 Turn on lazy global initializers.
Swift SVN r11136
2013-12-11 18:59:56 +00:00
Joe Groff
4a25b56846 SILGen: REPL globals are not lazily initialized.
Check for a REPL SourceFileKind along with Main before going the lazy initialization path. Also put response variables in the REPL SourceFile decl context so they are recognized as REPL variables and not lazily initialized. Handle PatternBindingDecls that appear under a script-mode SourceFile decl context but not a TopLevelCodeDecl context.

Swift SVN r11133
2013-12-11 17:54:17 +00:00
Joe Groff
3688e6f60e SILGen: Don't try to emit lazy initializers for globals from Clang.
Swift SVN r11132
2013-12-11 17:54:16 +00:00
Chris Lattner
698380d6d3 Introduce a new bit in VarDecl, "isLet". Teach Sema that 'isLet' properties
are not settable (like get-only ones).  Set the 'isLet' bit in various 
places, but not the particularly interesting or useful places yet.



Swift SVN r11121
2013-12-11 06:45:40 +00:00
Adrian Prantl
2acb71831e SILArgument: Make Decls mandatory for function arguments.
Swift SVN r11099
2013-12-10 23:30:23 +00:00
Adrian Prantl
1f927d9ffc Overhaul the handling of return locations for auto-generated code.
- change SILGenFunction to use Cleanup and Implicit return locations for
  auto-generated cleanups/returns where sensible.
- Fix a bug in where ConstructorDecl that would return the wrong
  source range.
- Move the expected locations of some errors to the end of the function
  where they should belong.

Fixes <rdar://problem/15609768> Line tables for classes that don't have
init but just initialize ivars are odd

Swift SVN r11086
2013-12-10 19:23:34 +00:00
Joe Groff
02a0e996c4 SIL: Kill initialize_var instruction.
Remove the initialize_var instruction now that DI fully diagnoses initialization problems. Change String-to-NSString bridging to explicitly invoke String's default constructor; it was the last remaining user of initialize_var. Remove dead code to emit an implicit default constructor without a body.

Swift SVN r11066
2013-12-10 03:36:59 +00:00
Anna Zaks
799fba7c63 Improve the location information for class and value initializer bodies.
This improves the error location information for DI diagnostics. rdar://15581664

Swift SVN r11062
2013-12-10 00:40:14 +00:00
Chris Lattner
8d997cdafb remove an unnecessary special case from SILGen. There is now only one last
use of initialize_var left, which is used in NSString bridging.  Once that
is gone (tracked by rdar://15568558, which I don't plan to do) then 
initialize_var can be removed as well.


Swift SVN r11054
2013-12-10 00:00:37 +00:00
Chris Lattner
39224db6a9 remove the ZeroValueExpr AST node.
Swift SVN r11048
2013-12-09 23:16:14 +00:00
Chris Lattner
51a5a3cd50 turn on DI for ObjC classes, resolving:
<rdar://problem/11937539> implement a definite initialization checker in swift

QoI and validating requirements on super.init (15579247) still remain.  This
also leaves a bunch of dead code in Sema, which I'll remove in a bit.


Swift SVN r11032
2013-12-09 17:48:07 +00:00
Joe Groff
e37897b57b SILGen: Always emit physical access to stored properties in 'init' and 'destructor', even for @objc stored properties.
This gives more predictable semantics for initializers and destructors under the DI model, and also unblocks enabling the DI model at all for @objc initializers. <rdar://problem/15614052>

Swift SVN r11029
2013-12-09 17:31:04 +00:00
Chris Lattner
375c92a4af Turn on DI for derived classes. Except for @objc classes, it now
ensures that all ivars in all cases are initialized before super.init
is called.

It is still not handling @objc classes, and still isn't enforcing that
super.init itself happens in the right places.  Also, the QoI could be
better


Swift SVN r11026
2013-12-09 16:44:22 +00:00
Chris Lattner
0aff0a2adc Turn on DI for init methods in root classes that are not marked ObjC.
We are inching towards DI world domination.



Swift SVN r11009
2013-12-09 06:05:01 +00:00
Chris Lattner
e07994c9c8 Two changes:
- Fix a misunderstanding I had about ownership requirements in my previous patch:
   now any references to value-promoted self do a retain and use a ManagedValue,
   just like the semantic load path used to.  This is the change to visitLoadExpr
 - Second, change argument lowering to drop the "self" argument of normal class
   methods into a constant reference, instead of making a box for it.  This 
   greatly reduces the amount of SIL generated for class methods.

The argument lowering piece is somewhat hacky because initializations really want
to be dealing with memory, but it seemed like the best approach given the current
design.  Review appreciated.



Swift SVN r10984
2013-12-07 21:30:38 +00:00
Chris Lattner
73ea257446 remove an old and apparently unnecessary hack in pattern lowering for arguments.
Disable the copyaddr peepholes when the loadexpr is from a constant VarDecl.


Swift SVN r10982
2013-12-07 08:19:38 +00:00
Chris Lattner
db0fe52b65 Introduce a new CaptureKind::Constant concept to SILGen, allowing it
to correctly form closures over 'constant' VarDecls like 'self' in 
some cases.


Swift SVN r10978
2013-12-07 05:48:59 +00:00
Chris Lattner
dec95a6890 At Joe's request, rename CaptureKind::Constant ->
CaptureKind::LocalFunction, and LocalConstants -> LocalFunctions


Swift SVN r10965
2013-12-07 01:25:30 +00:00
Chris Lattner
0e271de509 introduce a new kind of VarLoc to SILGen: "constant". This
is used for VarDecls that are immutable once defined.  This 
will eventually be used to model 'val' in SILGen, but for now
we can use it to optimize some 'self' situations.

At present, we use it for class 'self' in destructors and for
init methods of root classes.  The init methods of derived 
classes need to be able to mutate self when calling super.init
so they can't use this presently.  I haven't gotten around to
switching general methods to use it yet.

This introduces two new regressions that don't appear in the
testsuite: we lose debug info for "self" in this case, and 
we cannot close over self.



Swift SVN r10962
2013-12-07 01:13:55 +00:00
Joe Groff
0ff977d407 Add a 'WitnessMethod' enumerator to AbstractCC.
We'll use this to represent the slightly-different polymorphic calling convention used for passing Self into protocol witnesses.

Swift SVN r10898
2013-12-06 01:32:35 +00:00
Adrian Prantl
2055386e0c Debug Info: Move the argument ordering logic into IRGenSILFunction and
get rid of the hack that used to be in IRGenDebugInfo.
This commit also adds a bunch of interesting testcases for function args.
Fixes <rdar://problem/15464454> Arguments sometimes go missing.

Swift SVN r10873
2013-12-05 18:51:07 +00:00
Chris Lattner
ba5351a761 remove the "allOfThis" initialized logic, which is dead now that
structs and enums are handled by DI.  You can't assign to self in 
a class ctor (not currently rejected, but presumably will be when
we have 'val').


Swift SVN r10871
2013-12-05 18:37:40 +00:00
Chris Lattner
c69c069d87 Enhance sema to know to never give imported C structs a default initializer,
they should always use their memberwise init method.

DI now handles all structs.


Swift SVN r10868
2013-12-05 18:24:16 +00:00
Chris Lattner
cdbeb696bb Turn on DI for struct init methods!
- Change silgen to generate mark_unintialized so DI does its thing.
 - Change Sema to not generate an init() method if some stored member has no initial value.
 - Change Sema to disable its horrible horrible heuristic that scans init() bodies to try to decide whether members are initialized. 
 - This doesn't handle structs imported from clang yet.



Swift SVN r10841
2013-12-05 01:56:47 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Doug Gregor
627f0ae447 Allow "x as T" to perform implicit conversions from x to T.
Fixes <rdar://problem/15283100>.


Swift SVN r10783
2013-12-04 17:31:44 +00:00
Chris Lattner
3289b6e455 Start emitting "mark_unitialized [rootself]" for the self argument of
enum ctors, and add minimal updates to DI to tolerate this.  Doing so 
exposed a bug that would cause DI to crash handling conditional 
destruction of mark_unintialized (which was never possible
before since globals aren't destructed).



Swift SVN r10778
2013-12-04 06:13:35 +00:00
Chris Lattner
aeddc57297 enable definite init for generic enums initializers as well.
Swift SVN r10733
2013-12-02 22:11:05 +00:00
Chris Lattner
5061ee57a8 stop emitting initialize_var instructions in enum constructors. This is
all we need to enable DI for enum constructors.  Structs and classes are
more complex, and the diagnostic produced is not great.  This resolves 
rdar://14922277.

Also, now an unreachable code diagnostic (with no source location) is 
produced when building the stdlib.  I'll investigate.


Swift SVN r10725
2013-12-02 17:35:38 +00:00
Chris Lattner
ad05efc481 Redesign the BuiltinFunctionRefInst to contain an Identifier instead of
a FuncDecl.  This makes it much more straight-forward for SIL passes to
introduce a new one - without doing name lookup in the builtin module!



Swift SVN r10694
2013-11-30 01:49:36 +00:00
Chris Lattner
07ce5306f3 add a SILType::isTrivial helper function.
Swift SVN r10610
2013-11-20 22:53:49 +00:00
Joe Groff
84ab2a47dc SILGen: Peephole physical lvalue-to-lvalue assignments.
When assigning between physical lvalues, emit a 'copy_addr' instead of a load + assign sequence. This provides a higher-level semantic instruction to SIL passes, and also produces better code in many cases.

It unfortunately exposes another bug in DI which affects the test/IRGen/objc.swift test, which I've XFAILed until it can be fixed.

Swift SVN r10564
2013-11-19 23:17:55 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
f6b1745650 SIL: Remove 'ModuleInst'.
Module values could never be used for anything, and we have SILUndef now, so when SILGen sees a ModuleExpr, we can just emit 'undef'.

Swift SVN r10548
2013-11-18 21:36:08 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Joe Groff
7b9f61de5c SILGen: Emit global var decl refs as calls to the accessor.
Route global var refs (except for those referencing top-level code vars) through the lazy-initializing global accessor functions for those globals.

Swift SVN r10519
2013-11-16 23:52:39 +00:00
Joe Groff
a049ee9d38 SILGen: (Optionally) emit lazy initializers and accessor fns for globals.
For every global pattern binding, emit a lazy initializer token and function that initializes the global variables in that binding. For each of those vars, create an accessor that Builtin.once's the lazy initializer before producing the address. Hide this all behind a switch till the surrounding serialization and IRGen infrastructure catches up.

Swift SVN r10511
2013-11-16 00:50:19 +00:00
John McCall
08171453da Make it a bit easier to propogate expressions around instead
of having to lower to an RValue.

This is valuable because we can often emit an expression to a
desired abstraction level more efficiently than just emitting
it to minimal abstraction and then generalizing.

Swift SVN r10455
2013-11-14 05:25:06 +00:00
Chris Lattner
4968cc208b A couple of related changes:
- Enhance SILBuilder::emitStrongRelease to be smarter.
- Start using emitStrongRelease in type lowering, SILGen,
  CapturePromotion (replacing its implementation of the
  same logic), and MandatoryInlining (one more place)
- Rename the primitive createStrongRetain/ReleaseInst
  instructions to lose their suffix.
- Now that createStrongRetain/ReleaseInst are not special
  cases from the naming perspective, remove some special cases
  from DeserializeSIL and ParseSIL.
  


Swift SVN r10449
2013-11-14 02:21:27 +00:00
Chris Lattner
9570e1fb0c Remove the "createStrongRetain" and "createStrongRelease" SILBuilder methods.
They are the same as createStrongRetainInst and createStrongReleaseInst, but
peephole away FunctionRefInst.  It turns out that there is only a couple
places in SILGen where this behavior is necessary, and this tramples on the
general pattern used in SILBuilder.


Swift SVN r10448
2013-11-14 02:00:41 +00:00
Doug Gregor
66b9f36ff5 When emitting sibling method calls, callect substitutions from all levels.
Previously, we were only looking at the innermost level, ignoring
outer generic types. Fixes the SILGen part of
<rdar://problem/15345742>, but IRGen issues remain.


Swift SVN r10418
2013-11-13 06:48:00 +00:00
Chris Lattner
425819ac07 Change the SIL string_literal instruction to produce three results
(the same way alloc_box returns two) instead of returning a tuple.

This eliminates a ton of tuple_extract instructions, which just
bloat the generated SIL.  This resolves rdar://15378135.



Swift SVN r10416
2013-11-13 06:43:09 +00:00
Doug Gregor
eb7ce396db Use VarDecl::get[GS]etterType() and SubscriptDecl::get[GS]etterType() in SILGen
Eliminate SILGen's own computation of getter/setter types in favor of
the AST methods to compute the same.


Swift SVN r9992
2013-11-06 06:53:13 +00:00
Joe Groff
1616276923 SILGen: Remove 'SILGenLValuePeepholes' flag.
r9931 fixes the crashes this exposes, so we can enable it by default now.

Swift SVN r9935
2013-11-04 22:54:54 +00:00
Joe Groff
18dd9335f3 SILGen: Factor abstraction change from branch in checked cast emission.
<rdar://problem/14835992> happens because, when we emitted a chain of checked casts for 'is' patterns in a 'switch', we would emit abstraction changes for each individual cast that required them. This is both redundant and makes cleaning up messier, because the number of branches with different stack heights increases. Instead, let's emit one abstraction change up front for all of the casts. No functionality change yet, but this is a step on the way to fixing <rdar://problem/14835992>.

Swift SVN r9921
2013-11-04 17:44:03 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Joe Groff
c57ea38b95 SILGen: Don't produce context arguments for captured typealiases.
If a local function tried to reference a local typealias, we were trying to emit a SIL variable reference and freaking out, causing <rdar://problem/15360605>. For now, don't emit any capture arguments for local typealiases. Any context a local typealias requires should be handled by capturing the external context's generic parameters.

Swift SVN r9865
2013-11-01 00:12:29 +00:00
Argyrios Kyrtzidis
e31c93add3 [AST] The ASTContext parameter in FuncDecl::getResultType() is not really needed.
Swift SVN r9798
2013-10-30 17:09:56 +00:00
Joe Groff
1ff79ff951 SILGen: Fix use-after-free in 'x?' codegen.
Forward the result before closing the scope so it's still good when we pass it on out of the optional evaluation.

Swift SVN r9773
2013-10-30 00:17:34 +00:00