Skip to content

[SIL] Don't print duplicated import decls #17084

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

Merged

Conversation

kitasuke
Copy link
Contributor

@kitasuke kitasuke commented Jun 9, 2018

Issue

If we pass a raw SIL file as input to sil-opt, we get duplicated import declarations like below.
Here is commands to reproduce

sil-opt

$sil-opt input.sil > output.sil

input.sil

sil_stage raw

import Builtin
import Swift
import SwiftShims

func foo() {}
...

output.sil

sil_stage raw

import Builtin
import Swift
import SwiftShims

import Builtin

import Swift

import SwiftShims

func foo() {}
...

swiftc

$swiftc -emit-sil input.sil > output.sil

input.sil

sil_stage raw

import Builtin
import Swift
import SwiftShims

func foo() {}
...

output.sil

sil_stage canonical

import Builtin
import Swift
import SwiftShims

import Builtin

import Swift

import SwiftShims

func foo() {}
...

Why

swiftc goes through ASTPrinter for each decl including ImportDecl in SILPrinter. So if we already have import decls in silgen, it prints the import decls twice in SILPrinter and ASTPrinter.

Fix

Let's skip to visit visitImportDecl so that we wouldn't have the duplicated import decls.

@slavapestov
Copy link
Contributor

Can you add a test?

@slavapestov slavapestov self-assigned this Jun 9, 2018
@kitasuke
Copy link
Contributor Author

kitasuke commented Jun 9, 2018

I added test/sil-opt/import-decls.silgen, but was it not enough to check import declarations?

@kitasuke
Copy link
Contributor Author

kitasuke commented Jun 9, 2018

I found out that this is not a specific issue for sil-opt. Same output is emitted when swiftc takes raw SIL to emit canonical SIL. Is it more appropriate to put the test case in test/SIL then?

@kitasuke kitasuke changed the title [sil-opt] Don't print duplicated import decls [SIL] Don't print duplicated import decls Jun 9, 2018
Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will still pass with your change reverted. You need to build and import a custom module. And as you said this is not specific to sil-opt and should be moved to test/SIL.

@kitasuke
Copy link
Contributor Author

Addressed your feedback. Hope I correctly understood what you suggested.

@slavapestov
Copy link
Contributor

Looks good, thanks!

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 07caabe into swiftlang:master Jun 12, 2018
@kitasuke
Copy link
Contributor Author

I really appreciate for your all the feedbacks!

@kitasuke kitasuke deleted the fix_duplicated_import_delc_for_sil-opt branch June 12, 2018 04:53
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.

2 participants