Skip to content
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

introduce import and export statements #1453

Merged
merged 224 commits into from
Jun 11, 2024
Merged

introduce import and export statements #1453

merged 224 commits into from
Jun 11, 2024

Conversation

sezna
Copy link
Contributor

@sezna sezna commented Apr 30, 2024

This PR introduces exports and imports. A namespace can export any symbol it has access to. External packages (consumers of this package) will only have access to explicitly exported items.

How it works

Exports are a type of Item, and they appear inside of namespaces (implicit or explicit). Exports are paths, which are resolved to local item ids in the resolver. They are then bound to the scope of that namespace. After that, the exported item is added to the api surface of the namespace.

When we support external package dependencies, we only want to allow importing of explicitly exported items. At that time, we will add a flag to the items to denote if they originate from an export.

This PR also supports export aliases: export Foo as Bar;

Glob imports work similarly to other languages: Foo.* brings in everything from Foo, while Foo.* as Bar brings in all of Foo, but aliased under a namespace Bar. For example, if function F() : Unit {} exists in Foo, then after importing via Foo.* as Bar, it would be available as Bar.F().

Copy link

Change in memory usage detected by benchmark.

Memory Report for bc22eb7

Test This Branch On Main Difference
compile core + standard lib 16618073 bytes 16619429 bytes -1356 bytes

Copy link

Benchmark for bc22eb7

Click to view benchmark
Test Base PR %
Array append evaluation 328.0±1.39µs 329.2±3.59µs +0.37%
Array literal evaluation 170.3±1.18µs 186.9±2.22µs +9.75%
Array update evaluation 406.9±2.26µs 408.0±2.83µs +0.27%
Core + Standard library compilation 18.5±0.38ms 21.9±0.65ms +18.38%
Deutsch-Jozsa evaluation 5.1±0.05ms 5.2±0.07ms +1.96%
Large file parity evaluation 33.9±0.07ms 34.2±0.61ms +0.88%
Large input file compilation 12.7±0.19ms 13.7±0.34ms +7.87%
Large input file compilation (interpreter) 47.6±1.38ms 52.1±1.08ms +9.45%
Large nested iteration 32.4±0.23ms 32.8±0.70ms +1.23%
Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample 1573.3±38.00µs 1595.2±72.74µs +1.39%
Perform Runtime Capabilities Analysis (RCA) on large file sample 7.9±0.13ms 8.2±0.16ms +3.80%
Perform Runtime Capabilities Analysis (RCA) on teleport sample 1426.8±29.84µs 1457.0±116.90µs +2.12%
Perform Runtime Capabilities Analysis (RCA) on the core and std libraries 28.2±0.15ms 28.7±0.18ms +1.77%
Teleport evaluation 91.8±3.81µs 91.1±3.96µs -0.76%

sezna and others added 3 commits May 31, 2024 11:57
Co-authored-by: Mine Starks <16928427+minestarks@users.noreply.github.com>
_branched off of #1469_

This PR mainly introduces glob imports in import statements, e.g.:

 ```
import Foo.*;
import Foo.Bar.* as Baz;
```
et cetera.

Glob imports work similarly to other languages: `Foo.*` brings in everything from `Foo`, while `Foo.* as Bar` brings in all of `Foo`, but aliased under a namespace `Bar`. For example, if `function F() : Unit {}` exists in `Foo`, then after importing via `Foo.* as Bar`, it would be available as `Bar.F()`.


Other incidental changes include:
- Improving the `Display` impl for `ImportOrExportItem`, for easier-to-read tests
Copy link

github-actions bot commented Jun 6, 2024

Change in memory usage detected by benchmark.

Memory Report for aee8f6d

Test This Branch On Main Difference
compile core + standard lib 16608437 bytes 16616885 bytes -8448 bytes

Copy link

github-actions bot commented Jun 6, 2024

Benchmark for aee8f6d

Click to view benchmark
Test Base PR %
Array append evaluation 340.9±2.38µs 328.5±1.76µs -3.64%
Array literal evaluation 184.3±4.61µs 197.3±4.57µs +7.05%
Array update evaluation 419.2±6.79µs 412.6±3.72µs -1.57%
Core + Standard library compilation 18.6±0.17ms 20.3±0.21ms +9.14%
Deutsch-Jozsa evaluation 5.1±0.04ms 5.1±0.04ms 0.00%
Large file parity evaluation 34.3±0.18ms 34.6±0.55ms +0.87%
Large input file compilation 12.4±0.13ms 12.5±0.26ms +0.81%
Large input file compilation (interpreter) 46.8±0.72ms 48.2±0.85ms +2.99%
Large nested iteration 33.3±0.16ms 32.6±0.27ms -2.10%
Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample 1570.9±32.53µs 1556.6±40.38µs -0.91%
Perform Runtime Capabilities Analysis (RCA) on large file sample 7.8±0.08ms 7.7±0.13ms -1.28%
Perform Runtime Capabilities Analysis (RCA) on teleport sample 1428.0±32.34µs 1417.7±32.89µs -0.72%
Perform Runtime Capabilities Analysis (RCA) on the core and std libraries 28.3±0.21ms 27.9±0.87ms -1.41%
Teleport evaluation 89.0±4.22µs 87.9±3.94µs -1.24%

Copy link

github-actions bot commented Jun 6, 2024

Change in memory usage detected by benchmark.

Memory Report for 1f2af71

Test This Branch On Main Difference
compile core + standard lib 16608437 bytes 16616885 bytes -8448 bytes

Copy link

github-actions bot commented Jun 6, 2024

Benchmark for 1f2af71

Click to view benchmark
Test Base PR %
Array append evaluation 334.4±3.73µs 328.9±5.54µs -1.64%
Array literal evaluation 186.9±1.27µs 177.3±2.25µs -5.14%
Array update evaluation 411.7±2.62µs 407.9±5.78µs -0.92%
Core + Standard library compilation 19.1±0.44ms 21.5±1.54ms +12.57%
Deutsch-Jozsa evaluation 5.1±0.04ms 5.1±0.04ms 0.00%
Large file parity evaluation 34.1±0.10ms 34.2±0.47ms +0.29%
Large input file compilation 12.6±0.15ms 13.0±0.58ms +3.17%
Large input file compilation (interpreter) 48.1±0.88ms 50.0±1.65ms +3.95%
Large nested iteration 33.0±1.16ms 32.4±0.57ms -1.82%
Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample 1575.1±45.29µs 1559.9±35.71µs -0.97%
Perform Runtime Capabilities Analysis (RCA) on large file sample 7.8±0.13ms 7.9±0.10ms +1.28%
Perform Runtime Capabilities Analysis (RCA) on teleport sample 1423.3±42.92µs 1428.0±47.08µs +0.33%
Perform Runtime Capabilities Analysis (RCA) on the core and std libraries 28.3±0.36ms 28.0±0.21ms -1.06%
Teleport evaluation 88.8±3.81µs 88.4±3.82µs -0.45%

compiler/qsc_parse/src/item.rs Outdated Show resolved Hide resolved
compiler/qsc_frontend/src/resolve/tests.rs Outdated Show resolved Hide resolved
compiler/qsc_codegen/src/qsharp.rs Outdated Show resolved Hide resolved
compiler/qsc_ast/src/ast.rs Show resolved Hide resolved
Copy link

Change in memory usage detected by benchmark.

Memory Report for 171a565

Test This Branch On Main Difference
compile core + standard lib 16685477 bytes 16693925 bytes -8448 bytes

Copy link

Benchmark for 171a565

Click to view benchmark
Test Base PR %
Array append evaluation 330.6±5.67µs 329.7±1.93µs -0.27%
Array literal evaluation 189.5±2.68µs 175.4±1.13µs -7.44%
Array update evaluation 411.1±2.96µs 407.5±3.06µs -0.88%
Core + Standard library compilation 22.1±0.90ms 24.5±2.64ms +10.86%
Deutsch-Jozsa evaluation 5.1±0.07ms 5.1±0.06ms 0.00%
Large file parity evaluation 34.1±0.22ms 34.2±0.57ms +0.29%
Large input file compilation 14.2±0.66ms 14.6±0.87ms +2.82%
Large input file compilation (interpreter) 55.0±2.07ms 53.7±1.84ms -2.36%
Large nested iteration 32.4±0.15ms 32.4±0.28ms 0.00%
Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample 1623.1±163.60µs 1601.9±92.27µs -1.31%
Perform Runtime Capabilities Analysis (RCA) on large file sample 8.2±0.22ms 8.2±0.19ms 0.00%
Perform Runtime Capabilities Analysis (RCA) on teleport sample 1475.8±110.32µs 1453.4±99.39µs -1.52%
Perform Runtime Capabilities Analysis (RCA) on the core and std libraries 29.0±0.35ms 28.7±0.67ms -1.03%
Teleport evaluation 88.8±4.31µs 88.0±3.57µs -0.90%

Copy link

Change in memory usage detected by benchmark.

Memory Report for 2119ad9

Test This Branch On Main Difference
compile core + standard lib 16685477 bytes 16693925 bytes -8448 bytes

Copy link

Benchmark for 2119ad9

Click to view benchmark
Test Base PR %
Array append evaluation 333.0±2.57µs 329.1±1.03µs -1.17%
Array literal evaluation 172.3±2.93µs 195.4±2.56µs +13.41%
Array update evaluation 412.9±2.16µs 408.8±3.41µs -0.99%
Core + Standard library compilation 20.5±0.97ms 21.4±0.85ms +4.39%
Deutsch-Jozsa evaluation 5.1±0.05ms 5.1±0.06ms 0.00%
Large file parity evaluation 34.0±0.08ms 34.0±0.82ms 0.00%
Large input file compilation 13.0±0.38ms 13.1±0.34ms +0.77%
Large input file compilation (interpreter) 49.9±1.22ms 51.6±1.15ms +3.41%
Large nested iteration 33.0±0.51ms 32.2±0.13ms -2.42%
Perform Runtime Capabilities Analysis (RCA) on Deutsch-Jozsa sample 1598.8±88.66µs 1580.2±62.41µs -1.16%
Perform Runtime Capabilities Analysis (RCA) on large file sample 8.1±0.33ms 8.0±0.11ms -1.23%
Perform Runtime Capabilities Analysis (RCA) on teleport sample 1449.5±45.09µs 1442.8±81.75µs -0.46%
Perform Runtime Capabilities Analysis (RCA) on the core and std libraries 28.5±0.28ms 28.6±0.44ms +0.35%
Teleport evaluation 89.2±4.10µs 87.8±4.13µs -1.57%

@sezna sezna enabled auto-merge June 11, 2024 21:09
@sezna sezna added this pull request to the merge queue Jun 11, 2024
Merged via the queue into main with commit 522206d Jun 11, 2024
16 checks passed
@sezna sezna deleted the alex/export-statements branch June 11, 2024 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants