Commit Graph

61 Commits

Author SHA1 Message Date
Slava Pestov
e212d4567f Sema: Collect varargs into an ArrayExpr and use DefaultArgumentExpr
Instead of building ArgumentShuffleExprs, lets just build a TupleExpr,
with explicit representation of collected varargs and default
arguments.

This isn't quite as elegant as it should be, because when re-typechecking,
SanitizeExpr needs to restore the 'old' parameter list by stripping out
the nodes inserted by type checking. However that hackery is all isolated
in one place and will go away soon.

Note that there's a minor change the generated SIL. Caller default
arguments (#file, #line, etc) are no longer delayed and are instead
evaluated in their usual argument position. I don't believe this actually
results in an observable change in behavior, but if it turns out to be
a problem, we can pretty easily change it back to the old behavior with a
bit of extra work.
2019-03-31 01:36:19 -04:00
Slava Pestov
d470e9df4d AST: Split off ArgumentShuffleExpr from TupleShuffleExpr
Right now we use TupleShuffleExpr for two completely different things:

- Tuple conversions, where elements can be re-ordered and labels can be
  introduced/eliminated
- Complex argument lists, involving default arguments or varargs

The first case does not allow default arguments or varargs, and the
second case does not allow re-ordering or introduction/elimination
of labels. Furthermore, the first case has a representation limitation
that prevents us from expressing tuple conversions that change the
type of tuple elements.

For all these reasons, it is better if we use two separate Expr kinds
for these purposes. For now, just make an identical copy of
TupleShuffleExpr and call it ArgumentShuffleExpr. In CSApply, use
ArgumentShuffleExpr when forming the arguments to a call, and keep
using TupleShuffleExpr for tuple conversions. Each usage of
TupleShuffleExpr has been audited to see if it should instead look at
ArgumentShuffleExpr.

In sequent commits I plan on redesigning TupleShuffleExpr to correctly
represent all tuple conversions without any unnecessary baggage.

Longer term, we actually want to change the representation of CallExpr
to directly store an argument list; then instead of a single child
expression that must be a ParenExpr, TupleExpr or ArgumentShuffleExpr,
all CallExprs will have a uniform representation and ArgumentShuffleExpr
will go away altogether. This should reduce memory usage and radically
simplify parts of SILGen.
2019-03-21 02:18:41 -04:00
Xi Ge
28daecad81 refactoring: add a defensive check for nullptr. rdar://48290050 2019-02-25 11:02:05 -08:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Jordan Rose
ac4a92a968 Merge pull request #19292 from jrose-apple/get-out-the-map
Minor improvements to the use of StringMap/StringSet
2018-09-14 10:52:59 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Jordan Rose
245b06b832 Use llvm::StringSet instead of StringMap where appropriate
That is, where we aren't using the value for anything.

No functionality change.
2018-09-13 15:15:24 -07:00
Slava Pestov
e520dd613b IDE: Remove hasAccess() checks 2018-09-05 16:51:42 -07:00
Xi Ge
bff3f8adcc Merge pull request #16983 from mohitathwani/SR-7292
[WIP] Generating member wise initializer with local refactoring
2018-07-26 13:05:08 -07:00
Mohit Athwani
ce1122921a SR-7292 - Refactoring tool for generating member wise init 2018-07-26 11:31:30 -07:00
Rintaro Ishizaki
711cef6869 [Refactoring] Fix crasher in switch with non-nominal subject type
rdar://problem/42098130
2018-07-24 18:07:07 +09:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Rintaro Ishizaki
1ca88478a8 [Refactoring] Handle TupleShuffleExpr in "convert to trailing closure"
Fixes crash in "Convert To Trailing Closure" action if call has
defaulted parameters. Handle `TupleShuffleExpr` properly.

rdar://problem/41093898
2018-06-18 16:18:58 +09:00
John McCall
69f4dd1ec9 Generalize accessor storage to preserve the original accessor list.
Only not NFC because it's detectable by source tools.
2018-06-16 18:16:31 -04:00
Rintaro Ishizaki
3c367e9227 [Refactoring] Simplify implementation of "move members to extension" action 2018-05-25 19:04:01 +09:00
Rintaro Ishizaki
db3020f031 [Refactoring] Disallow several kinds of decl to move to extension
* AccessorDecl and EnumElementDecl aren't independent decls
* DestructorDecl and EnumCaseDecl can't be put in extension
2018-05-25 19:04:01 +09:00
Rintaro Ishizaki
025f4dde55 Merge pull request #16789 from rintaro/refactoring-nested-if
[Refactoring] Re-implement "collapse nested if" action
2018-05-24 07:56:02 +09:00
Rintaro Ishizaki
70ff0c013b [Refactoring] Disallow extracting partial statement
`BraceStmt`, `CatchStmt` and `CaseStmt` cannot be independent
statement, thus unextractable.

rdar://problem/38390401
2018-05-23 18:03:27 +09:00
Rintaro Ishizaki
639fb85c5f [Refactoring] Rename CollapseNestedIfExpr to CollapseNestedIfStmt
'if' is not expression, but statement.
2018-05-23 17:13:35 +09:00
Rintaro Ishizaki
f1c8230b2a [Refactoring] Re-implement "collapse nested if" action
Narrowed `isApplicable()` condition to ensure that we don't emit this
action when it's not safe to apply this action.

Fixes rdar://problem/39516354
2018-05-23 17:13:35 +09:00
Huon Wilson
75313cfed5 [IDE] make replace.bodies.with.fatalError an internal refactoring.
This shouldn't be exposed to general users.
2018-04-17 09:05:26 +10:00
Huon Wilson
fac1a529fe [IDE] Tweak replace.bodies.with.fatalError.
The menu item should be capitalised, and it's nicer if the fatalError is on its
own line in the new function body.
2018-04-16 12:58:55 +10:00
Huon Wilson
8056102ee5 [IDE] Refactoring to change function bodies to "fatalError()".
This is immensely useful when working on generic code, where the signatures
of (many) functions are all that is required, and removing the bodies makes
things compile faster, allows tools like creduce to work better and results in
less noise in a debugger.

Unfortunately the design of refactoring means this currently only works on a
single top-level decl, or multiple decls inside a type.
2018-04-13 15:56:56 +10:00
Rintaro Ishizaki
53be298f1f [IDE] Don't emit “Convert to Trailing Closure” for trailing closure (#15824)
rdar://problem/39253640
2018-04-09 15:30:52 +09:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Sho Ikeda
25cdc981c7 Merge pull request #14977 from ikesyo/gardening-use-empty
[gardening] Use `empty()` over `size() == 0`
2018-03-07 09:34:26 +09:00
Nathan Hawes
743d3a5f44 Merge pull request #14980 from nathawes/rdar37905156-rename-init-gives-empty-categorised-edit-ranges
[refactoring] Avoid producing empty string/comment categorized edit ranges when renaming init. Also disallow renaming inits with no arguments.
2018-03-06 15:40:22 -08:00
Nathan Hawes
91ec9982a8 [refactoring] Avoid producing empty categorised edit ranges when renaming init. Also disallow renaming inits with no arguments. 2018-03-05 18:38:35 -08:00
Xi Ge
2f47af6c7c refactoring: don't assume every pattern binding has an initializer. rdar://38062772 2018-03-05 16:14:09 -08:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
David Ungar
a9819b6e60 Renaming FrontendInputs -> FrontendInputsAndOutputs
Fix comment in ArtsToFrontendOptionsConverter re getOutputFilenamesFromCommandLineOrFilelist
2018-01-30 18:54:38 -08:00
Xi Ge
cf36346021 refactoring: when RangeInfo is of kind PartOfExpression, we should use the dedicated field to get the parent expression. rdar://36755861 (#14088) 2018-01-23 12:53:50 -08:00
Xi Ge
a73b767bf6 refactoring: add a defensive check against null type. rdar://36305791 (#14014) 2018-01-18 17:28:54 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Xi Ge
7945b7db53 refactoring: Add a defensive check for empty nodes list. (#13765)
This defensive check ensures convert-to-string-interpolation
refactoring doesn't continue when the selected AST nodes are empty.
We shouldn't need this check since the range info kind already implies its validity.

Tentatively fixing: rdar://35492432
2018-01-08 10:55:32 -08:00
Roman Roibu
b2d122c4a7 [IDE] Refactoring: Expand a ternary operator into an if statement and vice-versa (#12554) 2017-12-21 12:40:30 -08:00
David Ungar
28b206008f FrontendInputs data structure redo.
- Outlaw duplicate input files, fix driver, fix tests, and add test.
- Reflect that no buffer is present without a (possibly pseudo) named file.
- Reflect fact that every input has a (possible pseudo) name.
- Break up CompilerInstance::setup.

Don't bail on dups.
2017-12-05 17:28:03 -08:00
Nathan Hawes
c326ec46c7 [Refactoring] Fix subscript rename
Adds support for renaming subscripts with external names, e.g.
subscript(x y: Int), and introduces a noncollapsible parameter name range for
subscript parameters, since these shouldn't be collapsed with an argument label
of the same name as function parameter names are.
2017-11-28 19:45:29 -08:00
Slava Pestov
13eb7606ce IDE: Use the is<> template instead of TypeBase::getKind() 2017-11-13 22:10:41 -08:00
Alex Hoppen
746bfc6d59 [Refactoring] Add refactoring action to move type members to extension (#12795)
This implements SR-6297.
2017-11-09 11:08:34 -08:00
Rintaro Ishizaki
a57199cf68 [refactoring] Implement "Convert to Trailing Closure" refactoring action 2017-10-16 00:42:05 -07:00
Kacper Harasim
8cd677eb1f [Refactoring] SR-6051 Expansion of switch statement missing cases (#12281) 2017-10-13 09:37:58 -07:00
David Ungar
47ee930a50 git-clang-format'ed 2017-10-08 23:56:03 -07:00
David Ungar
c1821755de NFC: First step (refactoring) towards speeding up compilation by having multiple primary files: Creates new class, FrontendInputs, to encapsulate InputFilenames, InputBuffers, and PrimaryInput, which were formerly in FrontendOptions. Add new instance variable, Inputs, to FrontendOptions in order to hold FrontendInputs.
Encapsulate uses of the variables in FrontendInputs with intention-describing functions. Move some code that sets these variables into FrontendInputs and FrontendOptions classes.

Create new FrontendInputs class to encapsulate InputFilenames, InputBuffers and PrimaryInput, which were formerly in Frontend.

Includes one change in SwiftEditor.cpp to resolve a merge conflict.
2017-10-08 10:20:37 -07:00
Kacper Harasim
1bec63d911 [IDE] Remove convenience function added to SourceEditConsumer 2017-09-28 10:21:00 -07:00
Kacper Harasim
c7b9307348 [Refactoring] CursorInfoResolver now properly handles cursor placement in OptionalTryExpr and ForceTryExpr, NFC (#12123) 2017-09-26 14:29:10 -07:00
Xi Ge
e6eb7df33a Refactoring tool: Ensure we don't need to check applicability again when performing automated code change. NFC (#12111) 2017-09-25 17:21:32 -07:00
Kacper Harasim
6fcb8308ff [IDE] Refactoring: conversion from “force try” to error handled version (#12063)
* [IDE] Refactoring: conversion from “force try” do error handled version

* Removed unnecessary empty line

* Changed name of the refactor

* Review fixes

* Fixed recognizing try_! location by CursorResolver

* Review fixes
2017-09-24 09:05:32 -04:00
Xi Ge
4e4f5ae6cf IDE: add a utility stream class to SourceEditorConsumer. NFC (#12069) 2017-09-22 16:37:05 -07:00
Kacper Harasim
80698a04b0 [IDE] SR-5745 Refactoring: converting strings concatenation expression to strings interpolation (#11944) 2017-09-19 13:37:42 -07:00