Commit graph

268 commits

Author SHA1 Message Date
Aleksey Kladov
8c86963d47 DynMap
This might, or might not help us to reduce boilerplate associated with
plumbing values from analysis to the IDE layer
2019-12-06 21:28:05 +01:00
bors[bot]
d3702c02cd
Merge #2481
2481: Remove obsolete comment r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-12-06 20:03:44 +00:00
Edwin Cheng
76ff5b7c15 Add tests 2019-12-06 23:48:45 +08:00
bors[bot]
6e10a9f578
Merge #2479
2479: Add expansion infrastructure for derive macros r=matklad a=flodiebold

I thought I'd experiment a bit with attribute macro/derive expansion, and here's what I've got so far. It has dummy implementations of the Copy / Clone derives, to show that the approach works; it doesn't add any attribute macro support, but I think that fits into the architecture.

Basically, during raw item collection, we look at the attributes and generate macro calls for them if necessary. Currently I only do this for derives, and just add the derive macro calls as separate calls next to the item. I think for derives, it's important that they don't obscure the actual item, since they can't actually change it (e.g. sending the item token tree through macro expansion unnecessarily might make completion within it more complicated).

Attribute macros would have to be recognized at that stage and replace the item (i.e., the raw item collector will just emit an attribute macro call, and not the item). I think when we implement this, we should try to recognize known inert attributes, so that we don't do macro expansion unnecessarily; anything that isn't known needs to be treated as a possible attribute macro call (since the raw item collector can't resolve the macro yet).

There's basically no name resolution for attribute macros implemented, I just hardcoded the built-in derives. In the future, the built-ins should work within the normal name resolution infrastructure; the problem there is that the builtin stubs in `std` use macros 2.0, which we don't support yet (and adding support is outside the scope of this).

One aspect that I don't really have a solution for, but I don't know how important it is, is removing the attribute itself from its input. I'm pretty sure rustc leaves out the attribute macro from the input, but to do that, we'd have to create a completely new syntax node. I guess we could do it when / after converting to a token tree.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2019-12-05 20:00:20 +00:00
Aleksey Kladov
518b5bf927 Remove obsolete comment 2019-12-05 17:55:38 +01:00
Florian Diebold
18f6a995d0 Add expansion infrastructure for derive macros 2019-12-05 17:23:09 +01:00
Aleksey Kladov
0c0ce1ae41 Introduce ChildFromSource 2019-12-05 16:55:54 +01:00
ice1000
d15f300268 Publicize file_id to make test_db compile 2019-12-05 08:37:39 -05:00
ice1000
006a583381 Use placeholder instead of Option 2019-12-05 08:33:29 -05:00
ice1000
7702f690a9 One pub function less is good! 2019-12-05 08:28:31 -05:00
ice1000
762915826a Reduce visibility, use struct instead of tuples 2019-12-05 08:19:27 -05:00
ice1000
088f50c0ab No block at the moment 2019-12-04 18:30:42 -05:00
ice1000
032eb3d68e Remove almost unused ModuleSource::new 2019-12-04 18:30:42 -05:00
ice1000
5c5f90ba57 Confluent ModuleSource usage 2019-12-04 18:30:42 -05:00
ice1000
38853459e3 Add ModuleSource::Block 2019-12-04 18:30:42 -05:00
ice1000
7cbedc50bc Fix test compilation 2019-12-04 18:30:42 -05:00
ice1000
1bb59a7d08 Three-state enum for module origin 2019-12-04 18:30:42 -05:00
ice1000
009437f5d9 Replace ra_hir_expand::either with crate 2019-12-03 11:07:56 -05:00
bors[bot]
ec164fbb68
Merge #2455
2455: Add BuiltinShadowMode r=flodiebold a=edwin0cheng

This PR try to fix #1905 by introduce an `BuiltinShadowMode` in name resolving functions. 

cc @flodiebold 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-12-01 11:13:25 +00:00
Edwin Cheng
cfc6e9e366 Remove some empty lines 2019-12-01 12:17:52 +08:00
Edwin Cheng
13c54685ff Use index instead of peekable 2019-12-01 12:14:35 +08:00
Edwin Cheng
5f11117733 Fix comment 2019-12-01 12:14:12 +08:00
Edwin Cheng
bb601e7eaf Add BuiltinShadowMode 2019-11-30 23:29:21 +08:00
oxalica
2cb684bbce
Reduce variants of Expr 2019-11-29 14:49:12 +08:00
oxalica
4992d2bf79
Infer range types 2019-11-29 03:10:16 +08:00
Aleksey Kladov
8f1f5a783a Move source-related traits to a separate module 2019-11-28 19:05:21 +03:00
Aleksey Kladov
e823c578c9 Use InFile for AstId 2019-11-28 16:02:38 +03:00
Aleksey Kladov
ccd1b0800a Rename Source -> InFile 2019-11-28 12:50:26 +03:00
Aleksey Kladov
1d14fd1737 Use Name::missing consistently 2019-11-27 23:22:20 +03:00
Aleksey Kladov
27b362b059 Reformat 2019-11-27 21:44:38 +03:00
Aleksey Kladov
d9a36a736b Rename module_id -> local_id 2019-11-27 21:31:51 +03:00
Aleksey Kladov
a87579500a Move Ty 2019-11-27 21:16:00 +03:00
Aleksey Kladov
825049bc62 Decouple 2019-11-27 12:34:26 +03:00
Aleksey Kladov
bed6869865 Cleanup 2019-11-26 22:56:07 +03:00
bors[bot]
3206b83a70
Merge #2418
2418: Hide MacroCallLoc outside hir_expand  r=matklad a=edwin0cheng

This PR refactor `MacroCallLoc` such that it  be hided to become implementation details of hir_expand. 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-11-26 18:34:15 +00:00
Edwin Cheng
447268ceac Hide MacroCallLoc 2019-11-27 01:33:08 +08:00
Aleksey Kladov
6fb4871f31 Add note 2019-11-26 19:30:57 +03:00
Aleksey Kladov
9bc8f1f4f8 Store names in TraitData 2019-11-26 17:44:43 +03:00
bors[bot]
4822d26540
Merge #2406
2406: Add hygiene information to SourceAnalyzer r=matklad a=edwin0cheng

This should fix https://github.com/rust-analyzer/rust-analyzer/pull/2392#issuecomment-557964686

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-11-26 13:18:03 +00:00
Aleksey Kladov
a443b5033c Id-ify Ty::Adt 2019-11-26 14:29:12 +03:00
Aleksey Kladov
e5eadb3390 Introduce hir::Type
It should provide a convenient API over more low-level Ty
2019-11-26 14:02:57 +03:00
Aleksey Kladov
131c2da6bf ⬆️ salsa 2019-11-26 11:29:20 +03:00
Edwin Cheng
245a9b165a Add hygiene information to SourceAnalyzer 2019-11-26 15:05:53 +08:00
Aleksey Kladov
1455663ea1 Fixme for union fields 2019-11-25 17:50:49 +03:00
Aleksey Kladov
5fd68b5929 Fix hir for ast::UnionDef 2019-11-25 17:50:49 +03:00
bors[bot]
f7f9757b6b
Merge #2396
2396: Switch to variant-granularity field type inference r=flodiebold a=matklad

r? @flodiebold 

Previously, we had a `ty` query for each field. This PR switcthes to a query per struct, which returns an `ArenaMap` with `Ty`s. 

I don't know which approach is better. What is bugging me about the original approach is that, if we do all queries on the "leaf" defs, in practice we get a ton of queries which repeatedly reach into the parent definition to compute module, resolver, etc. This *seems* wasteful (but I don't think this is really what causes any perf problems for us). 

At the same time, I've been looking at Kotlin, and they seem to use the general pattern of analyzing the *parent* definition, and storing info about children into a `BindingContext`. 

I don't really which way is preferable. I think I want to try this approach, where query granularity generally mirrors the data granularity. The primary motivation for me here is probably just hope that we can avoid adding a ton of helpers to a `StructField`, and maybe in general avoid the need to switch to a global `StructField`, using `LocalStructFieldId` most of the time internally. 

For external API (ie, for `ra_ide_api`), I think we should continue with fine-grained `StructField::ty` approach, which internally fetches the table for the whole struct and indexes into it.

In terms of actual memory savings, the results are as follows:

```
This PR:
   142kb FieldTypesQuery (deps)
    38kb FieldTypesQuery

Status Quo:
   208kb TypeForFieldQuery (deps)
    18kb TypeForFieldQuery
```

Note how the table itself occupies more than twice as much space! I don't have an explanation for this: a plausible hypothesis is that single-field structs are very common and for them the table is a pessimisation. 

THere's noticiable wallclock time difference.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-11-24 21:45:26 +00:00
Aleksey Kladov
d06904e90c Switch to variant-granularity field type inference 2019-11-25 00:12:36 +03:00
Aleksey Kladov
a0e1dbb450 Implement HasModule for AdtId 2019-11-24 22:48:37 +03:00
Aleksey Kladov
586acef528 Simplify ADT fields 2019-11-24 22:44:24 +03:00
Aleksey Kladov
d87c16bea6 hir_def is fully doc'ed! 2019-11-24 21:00:50 +03:00
Aleksey Kladov
d157812cd1 Docs 2019-11-24 20:39:48 +03:00
Aleksey Kladov
63e3ea38d3 Don't redo field resolution in the IDE 2019-11-24 20:06:55 +03:00
Aleksey Kladov
434f108ada Simplify 2019-11-24 19:01:19 +03:00
Aleksey Kladov
f5e0a31eaf Cleanup nameres 2019-11-24 18:05:12 +03:00
Aleksey Kladov
855a629b14 Use Trace in raw_items 2019-11-24 17:49:49 +03:00
Aleksey Kladov
21cfa6d529 Some docs 2019-11-24 17:36:06 +03:00
Aleksey Kladov
99af523b68 Cleanup 2019-11-24 17:36:06 +03:00
Aleksey Kladov
326f066aa2 Reduce visibility 2019-11-24 17:36:06 +03:00
Aleksey Kladov
4b74fb1d89 Nicer API for attrs 2019-11-24 16:03:02 +03:00
Aleksey Kladov
1956d57ed4 Slightly reduce code duplication 2019-11-24 15:50:45 +03:00
Aleksey Kladov
8e36cb5860 Simplify 2019-11-24 15:28:45 +03:00
Aleksey Kladov
151180057b Simplify 2019-11-24 15:20:59 +03:00
Aleksey Kladov
e0b06cb672 Switch to StaticLoc for statics 2019-11-24 15:18:12 +03:00
Aleksey Kladov
53506a7552 Pull macro up 2019-11-24 14:13:51 +03:00
Aleksey Kladov
cfffea6dc8 Push poison_macros down 2019-11-24 13:57:45 +03:00
Aleksey Kladov
f0e0a40a61 Reduce visbility 2019-11-24 13:34:27 +03:00
Aleksey Kladov
ffc2325d19 Move ModuleSource back to hir 2019-11-23 17:12:49 +03:00
Aleksey Kladov
6bdd5fa461 Privatise nameres 2019-11-23 17:12:49 +03:00
Aleksey Kladov
158b1cb524 Rename CrateModuleId 2019-11-23 17:12:49 +03:00
Aleksey Kladov
dd5c2dc5bf Move ImportId 2019-11-23 16:49:05 +03:00
Aleksey Kladov
8efc41e7f2 Cleanup imports 2019-11-23 15:33:21 +03:00
Aleksey Kladov
fc1e543f7a Get rid of DefDatabase2 2019-11-23 14:49:45 +03:00
Aleksey Kladov
958862093e Move docs to hir_def 2019-11-23 14:43:38 +03:00
Aleksey Kladov
8692977d27 Move lang_items to hir_def 2019-11-23 12:58:01 +03:00
Aleksey Kladov
1a99864963 Use attrs rather than syntax for lang items 2019-11-23 12:01:56 +03:00
Aleksey Kladov
552ba868af Move attrs query to hir_def 2019-11-23 11:14:40 +03:00
Aleksey Kladov
0f415dd4b3 More principled sources for enums and fields 2019-11-22 23:09:17 +03:00
Aleksey Kladov
d8caf56dfc Uniformalize naming 2019-11-22 21:52:06 +03:00
Aleksey Kladov
d4f4ae0dd8 Move const&static date to hir_def 2019-11-22 18:46:39 +03:00
Aleksey Kladov
64df759418 Make ImplData's fields public 2019-11-22 17:42:56 +03:00
Aleksey Kladov
b315f05cf1 Move data to a single file 2019-11-22 17:32:10 +03:00
Aleksey Kladov
78f3b0627c Move FunctionData to hir_def 2019-11-22 17:18:04 +03:00
bors[bot]
5be7bd605a
Merge #2348 #2352
2348: Add support for stringify! builtin macro r=matklad a=piotr-szpetkowski

Refs #2212

First time ever contributing here, hopefully it's ok.

2352: Move TypeAlias to hir_def r=matklad a=matklad



Co-authored-by: Piotr Szpetkowski <piotr.szpetkowski@pyquest.space>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-11-22 10:14:41 +00:00
Aleksey Kladov
4fc900deb1 Move TypeAlias to hir_def 2019-11-22 13:13:51 +03:00
Aleksey Kladov
e42f962766 Encapsulate Attrs 2019-11-22 11:27:47 +03:00
Aleksey Kladov
a1346bba5c Fix test mark placement 2019-11-21 17:09:38 +03:00
Aleksey Kladov
4f8f3393bc Reduce visibility 2019-11-21 16:00:57 +03:00
Aleksey Kladov
36758f2767 Resimplify 2019-11-21 15:56:27 +03:00
Aleksey Kladov
c37d1c5b38 Restore a mark 2019-11-21 15:49:24 +03:00
Aleksey Kladov
6d64798a23 Move resolver to hir_def 2019-11-21 15:39:09 +03:00
Aleksey Kladov
0102fb4133 Decouple Resolver 2019-11-21 13:25:03 +03:00
Aleksey Kladov
12ec946216 Simplify generic params 2019-11-20 20:50:34 +03:00
Aleksey Kladov
cb642fc578 Move generic_params query to HIR 2019-11-20 20:38:37 +03:00
Aleksey Kladov
111891dc2d Move constants to new ID
This allows us to get rid of trait item index
2019-11-20 18:41:23 +03:00
Aleksey Kladov
ee95a35664 Don't duplicate ContainerId type 2019-11-20 17:50:02 +03:00
Aleksey Kladov
64c21ed195 Switch type aliases to new sources 2019-11-20 17:43:03 +03:00
Aleksey Kladov
cebeedc66f Next gen IDs for functions
The current system with AstIds has two primaraly drawbacks:

* It is possible to manufacture IDs out of thin air.
  For example, it's possible to create IDs for items which are not
  considered in CrateDefMap due to cfg. Or it is possible to mixup
  structs and unions, because they share ID space.

* Getting the ID of a parent requires a secondary index.

Instead, the plan is to pursue the more traditional approach, where
each items stores the id of the parent declaration. This makes
`FromSource` more awkward, but also more correct: now, to get from an
AST to HIR, we first do this recursively for the parent item, and the
just search the children of the parent for the matching def
2019-11-20 16:22:58 +03:00
Aleksey Kladov
06fa3d8389 Move traits to hir_def 2019-11-20 14:22:38 +03:00
Aleksey Kladov
e1a6e38767 Move Generics to hir_def 2019-11-20 12:34:48 +03:00
Aleksey Kladov
36e3fc9d54 Rename Source::ast -> Source::value 2019-11-20 09:42:30 +03:00
Aleksey Kladov
7e2f4b30db Disable doctests 2019-11-17 18:35:05 +03:00
Aleksey Kladov
892671926b Remove wrong clone 2019-11-16 01:00:00 +03:00
Aleksey Kladov
4c90b7e2ec Sourcify some things
If we want to support macros properly, we need to get rid of those
FileIds everywhere...
2019-11-15 23:24:56 +03:00
Aleksey Kladov
b21829f7ed Remove old impls infrastructure 2019-11-15 21:35:03 +03:00
Aleksey Kladov
ea3540c1a8 Store impls in CrateDefMap 2019-11-15 21:19:32 +03:00
Aleksey Kladov
080dd31f84 Add ImplId 2019-11-15 21:19:32 +03:00
Aleksey Kladov
aeb5e061a8 Reduce visibility 2019-11-15 21:19:32 +03:00
Aleksey Kladov
2f6c0c314b Move scope tests to hir_def 2019-11-15 14:47:26 +03:00
Aleksey Kladov
5766ceab06 Add convenience method for testing 2019-11-15 13:16:30 +03:00
Aleksey Kladov
a28907af8c Privatize modules 2019-11-15 10:42:54 +03:00
Aleksey Kladov
9c7a2aef30 Refactor Module::from_source to properly descend from root file 2019-11-15 10:26:31 +03:00
Aleksey Kladov
1583ab1558 Move body queries to hir_def 2019-11-14 17:37:22 +03:00
Aleksey Kladov
f924ae3b86 Move scopes to hir_def 2019-11-14 11:56:13 +03:00
Aleksey Kladov
4efd345b09 Slightly better naming 2019-11-14 11:33:48 +03:00
Aleksey Kladov
da2ca01eba Handle macro-generated expressions slightly less wrong 2019-11-14 10:30:30 +03:00
Aleksey Kladov
a73b7bb3f6 Move expansion to Expander 2019-11-14 10:04:39 +03:00
Aleksey Kladov
5c720b256f Move parse_path to Expander 2019-11-14 09:58:39 +03:00
Aleksey Kladov
e7880db1d0 Expansion stack scaffold 2019-11-14 09:57:57 +03:00
Aleksey Kladov
c89010df2d Add Expader::to_source 2019-11-14 09:57:57 +03:00
Aleksey Kladov
e7e85c60d2 Move original_file to Expander 2019-11-14 09:55:24 +03:00
Aleksey Kladov
8c8ef1432e Rename MacroResolver -> Expander 2019-11-14 09:38:25 +03:00
Aleksey Kladov
b3175b7077 Move current file to MacroResolver 2019-11-14 09:37:33 +03:00
Aleksey Kladov
debf95eb1b Reduce visibility 2019-11-14 09:24:39 +03:00
Aleksey Kladov
fe5e74e083 Add helpful pointer to module docs 2019-11-12 18:53:26 +03:00
Aleksey Kladov
1c0a3a1a30 Drop obsolete comment 2019-11-12 18:51:37 +03:00
Aleksey Kladov
1a90ad5802 Move expression lowering to hir_def 2019-11-12 18:46:57 +03:00
Aleksey Kladov
d09e5a3d9e Move definition of exprs to hir_def 2019-11-12 15:09:25 +03:00
Aleksey Kladov
f5e1b0f97c Minor refactoring 2019-11-12 12:07:47 +03:00
bors[bot]
ef2a9aedb6
Merge #2205
2205: Implement bulitin line! macro r=matklad a=edwin0cheng

This PR implements bulitin macro `line!` and add basic infra-structure for other bulitin macros:

1. Extend `MacroDefId` to support builtin macros
2. Add a `quote!` macro for simple quasi quoting.

Note that for support others builtin macros, eager macro expansion have to be supported first, this PR not try to handle it. :)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-11-11 10:53:24 +00:00
Edwin Cheng
4f7df2aac1 Add MacroDefKind 2019-11-11 18:48:16 +08:00
Aleksey Kladov
5bb92c2d1a impl fmt::Display for BuiltinType 2019-11-11 11:59:19 +03:00
Edwin Cheng
c46768d13d Add basic bultin macro infrastructure 2019-11-11 14:13:31 +08:00
Matthias Einwag
d634364462 Overwrite the prelude with one defined in a later dependency
This removes the special casing for the "core" prelude.
Whenever a later dependency also exports a prelude, it will replace
the formerly imported prelude.  The utilized prelude then depends
purely on import order.
2019-11-10 13:15:47 -08:00
Matthias Einwag
8baa05666c Add tests for resolving types in core and std preludes 2019-11-09 17:38:08 -08:00
Matthias Einwag
799903ba16 Resolve core types
This adds support for completion and goto definition of
types defined within the "core" crate. The core crate is
added as a dependency to each crate in the project.

The core crate exported it's own prelude. This caused
now all crates to inherit the core crates prelude instead
of the std crates. In order to avoid the problem the
prelude resolution has been changed to overwrite
an already resolved prelude if this was set to a crate
named core - in order to pick a better prelude like std.

Fixes #2199
2019-11-09 15:22:19 -08:00
Aleksey Kladov
6294fd5ec9 Unfork struct and union ids 2019-11-09 15:34:00 +03:00
Aleksey Kladov
c626a677e8 Touch up nameres doc comment 2019-11-09 00:23:19 +03:00
Aleksey Kladov
657340e078 Reduce visibility 2019-11-09 00:23:11 +03:00
Aleksey Kladov
53945841be Extract path resolution submodule 2019-11-09 00:17:17 +03:00
Aleksey Kladov
785887b382 Simplify
There's only one call-site for the function, so it seems fine to
inline
2019-11-08 23:53:39 +03:00
Aleksey Kladov
dc5e5f610c Reduce visibility 2019-11-08 23:47:52 +03:00
Aleksey Kladov
93d9e8a06f Reduce visibility 2019-11-04 23:37:35 +03:00
Aleksey Kladov
739babc391 Move Namespace enum closer to usage 2019-11-04 23:02:35 +03:00
Aleksey Kladov
d04ecc8419 Reduce visibility 2019-11-04 21:42:25 +03:00
Aleksey Kladov
3603d02134 Reexport relative_path from ra_db 2019-11-04 01:14:17 +03:00
Aleksey Kladov
8922a44395 Add small module-level docs 2019-11-04 00:23:14 +03:00
Aleksey Kladov
f0eb9cc6e6 Remove last traces of nameres from hir 2019-11-03 23:49:44 +03:00
Aleksey Kladov
73fcf9a2d6 Restore crate_def_map marks 2019-11-03 23:44:23 +03:00
Aleksey Kladov
6fba51c5fc move crate_def_map tests to hir_def 2019-11-03 23:35:48 +03:00
Aleksey Kladov
0933d914a3 Introduce ra_db::fixture fixture module
The goal here is to share more testing infrastructure between crates.
2019-11-03 20:55:20 +03:00