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

[SR-14587] refactor-check-compiles should generate both -dump-text and dump-rewritten from a single swift-refactor invocation #56939

Closed
ahoppen opened this issue May 4, 2021 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers

Comments

@ahoppen
Copy link
Contributor

ahoppen commented May 4, 2021

Previous ID SR-14587
Radar rdar://problem/77496418
Original Reporter @ahoppen
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, StarterBug
Assignee jiaren wang (JIRA)
Priority Medium

md5: 458dfb2ad5767bae122573a9d4e0a092

Issue Description:

At the moment refactor-check-compiles invokes swift-refactor twice, once to generate the output for -dump-text and once to generate the output for -dump-rewritten. This is duplicated effort. We should instead add an option to swift-refactor that outputs -dump-text to stdout and the contents of -dump-rewritten to a file. That way we could be generating both representations at the same time.

If anyone wants to tackle this as a starter bug:

  • You would need to add a new flag like -rewritten-output-file in swift-refactor.cpp that dumps the rewritten text to the specified output file, just like the DumpType::REWRITTEN case does today here

  • Afterwards, you’d need to update refactory-check-compiles.py to use that new argument to swift-refactor to retrieve the rewritten code together with the invocation that has -dump-rewritten, getting rid of the path that calls -dump-text and writes its stdout to the temp file.

@ahoppen
Copy link
Contributor Author

ahoppen commented May 4, 2021

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by jiaren wang (JIRA)

@ahoppen Like This?

def main():
    (args, unknown_args) = parse_args()
    temp_file_name = os.path.split(args.source_filename)[-1] + '.' + \
        args.pos.replace(':', '.')
    temp_file_path = os.path.join(args.temp_dir, temp_file_name)

    dump_rewritten_output = run_cmd([
        args.swift_refactor,
        '-dump-rewritten',
        '-source-filename', args.source_filename,
        'rewritten-output-file', temp_file_path,
        '-pos', args.pos
    ] + unknown_args, desc='producing rewritten file')

    run_cmd([
        args.swift_frontend,
        '-typecheck',
        temp_file_path,
        '-disable-availability-checking'
    ], desc='checking that rewritten file compiles')
    sys.stdout.write(dump_rewritten_output)

@ahoppen
Copy link
Contributor Author

ahoppen commented May 14, 2021

Hi jiaren wang (JIRA User),

Thanks for taking a look at this. The Python code looks good so far. Once you’ve got the changes for swift-refactor.cpp ready, could you open a PR on, so we can discuss them there? For that, I suggest you look at what we’re already doing for -dump-rewritten and at llvm::raw_fd_ostream to redirect the output to a file instead of stdout.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants