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

rustc needs sensible options for the emission of LLVM IR/LLVM bitcode/ASM #7791

Closed
chris-morgan opened this issue Jul 15, 2013 · 16 comments · Fixed by #12020
Closed

rustc needs sensible options for the emission of LLVM IR/LLVM bitcode/ASM #7791

chris-morgan opened this issue Jul 15, 2013 · 16 comments · Fixed by #12020
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler
Milestone

Comments

@chris-morgan
Copy link
Member

At present,

  • rustc foo.rs emits a binary;
  • rustc --emit-llvm foo.rs emits LLVM bitcode;
  • rustc -S foo.rs emits the final Assembler code;
  • rustc --emit-llvm -S foo.rs emits LLVM IR.

This is madness!

Here is my desired behaviour:

  • rustc --emit-binary foo.rs emits a binary;
  • rustc --emit-llvm-bc foo.rs emits LLVM bitcode;
  • rustc --emit-asm foo.rs emits the final Assembler code;
  • rustc --emit-llvm-ir foo.rs emits LLVM IR.

More than one of these options may be specified, in which case multiple things would be built; if no --emit-* option is specified, it will of course default to --emit-binary.

A brief look at the code suggests that at present it is only designed to produce one of these. An alternative, if staying within this constraint, would be --emit=(binary|llvm-(bc|ir)|asm); however, I feel allowing multiple outputs would be nicer, though I guess just -o wouldn't cut it.

@huonw
Copy link
Member

huonw commented Jul 15, 2013

Allowing multiple --emit=foo arguments might also work, and provides a natural grouping for documentation purposes, e.g. rustc --emit=binary --emit=asm my-file.rs and/or rustc --emit=binary,asm my-file.rs.

@chris-morgan
Copy link
Member Author

@huonw When I was thrashing the idea out in #rust last night I considered both those forms, but decided --emit-* to be nicer than --emit=* if only one is supported. The latter option, --emit=binary,asm, is much of a muchness with --emit-binary --emit-asm, I feel.

@mstewartgallus
Copy link
Contributor

I would support having --emit=binary,asm because then arguments later on could override previous arguments which is useful for makefiles. For example, suppose one had a makefile that had a RUST_FLAGS parameter, and invokes rustc as rustc --emit=binary mycrate.rs $(RUST_FLAGS). Then one could set RUST_FLAGS to --emit=asm, and only get assembler code produced, and not have the binary code produced. One problem that I still have not figured out is how the names of the outputs could be specified.

@chris-morgan
Copy link
Member Author

@sstewartgallus assuming a default of --emit=binary (the only sensible default, of course), one would not be expected to ever actually provide --emit=binary as in your example.

How this fits in with -o is also an interesting question.

@emberian
Copy link
Member

emberian commented Jan 6, 2014

Concrete proposal:

--emit={bin,lib,rlib,asm,ir,bc}

Merges --rlib/--lib/--bin into it. -o will only be able to be provided if only one emit is given. Alternatively, could have --emit bin=foo,lib=foo.so,rlib=foo.rlib,asm=foo.s,ir=foo.ll,bc=foo.bc and control it that way.

@alexcrichton?

@alexcrichton
Copy link
Member

I do like the idea of consolidating what is now like 8 flags into one, although there's one complication that I can think of. Currently the lib/bin distinction affects codegen in terms of visibility of functions, so with --emit you don't necessarily have a method of saying "output the library IR and output the executable IR".

I suppose we could default to "output the library IR", but if you're debugging IR for reachability optimizations you may not want that. I think I'd be ok with this as the default.

I do like the idea of one --emit though, and I think that the comma-separated list of type[=dest] is a good idea as well. I think that -o will definitely "just fall into place" after this is done.

Nominating, I'm mostly a fan of this proposal and if we're doing this for 1.0 we need to remove the existing flags sooner rather than later.

@emberian
Copy link
Member

emberian commented Jan 6, 2014

Hm. Let's take a hint from ad-hoc URL protocol composition! --emit rlib+ir=foo.ll The valid LHS of + are bin,lib,rlib, the valid RHS are
ir,asm,bc.

@huonw
Copy link
Member

huonw commented Jan 6, 2014

What about: --crate-type=rlib,lib,bin,... and --emit=asm,ir,... rather than trying to merge the two in an ad-hoc way.

@alexcrichton
Copy link
Member

This just gets more and more appealing!

--crate-type=rlib,lib,bin,staticlib,dylib
--emit=asm,bc,ir,obj,<xx>

That's the full and complete list I can think of, although <xx> is the name of "just finish compilation and output that", but I'm not sure of a good name for that (obj is foo.o)

@emberian
Copy link
Member

emberian commented Jan 7, 2014

<xx> could be final, complete, or maybe linked.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 7, 2014

Can we keep -S on its own as a shorthand for whatever the long option is for emitting the final Assembler code? Its a reasonably standard convention for native code compilers, no?

@brson
Copy link
Contributor

brson commented Jan 9, 2014

we should also consider compatibility with clang's flags

@pnkfelix
Copy link
Member

pnkfelix commented Jan 9, 2014

accepted for first major release, P-back-compat-libs

@emberian
Copy link
Member

I don't really like maintaining cli flag compatibility with other compilers. It seems incredibly unimportant, since we're not aiming to be a drop-in replacement for any compiler (unlike clang/icc which aim to emulate gcc)

@brson
Copy link
Contributor

brson commented Jan 17, 2014

Also should consider #612 and potential future isomorphisms between command line flags and crate attributes.

@alexcrichton
Copy link
Member

I've attempted a scheme in #12020 with --emit and --crate-type.

bors added a commit that referenced this issue Feb 6, 2014
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:

* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]

The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.

The new logic for files that rustc emits is as follows:

1. Output types are dictated by the --emit flag. The default value is
   --emit=link, and this option can be passed multiple times and have all options
   stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
   attribute. The flags can be passed many times and stack with the crate
   attribute.
3. If the -o flag is specified, and only one output type is specified, the
   output will be emitted at this location. If more than one output type is
   specified, then the filename of -o is ignored, and all output goes in the
   directory that -o specifies. The -o option always ignores the --out-dir
   option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the directory of
   the crate file.
6. When multiple output types are specified, the filestem of all output is the
   same as the name of the CrateId (derived from a crate attribute or from the
   filestem of the crate file).

Closes #7791
Closes #11056
Closes #11667
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 21, 2021
…type, r=giraffate

Allow giving reasons for `disallowed_types`

Similar to rust-lang#7609 but for the `disallowed_type` lint. The permitted form of configuration is the same as for `disallowed_methods`.

changelog: Allow giving reasons for [`disallowed_type`]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: rustc_driver that ties everything together into the `rustc` compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants