1
Fork 0
rust/compiler/rustc_middle/src/ty
Nicholas Nethercote 1acbe7573d Use delayed error handling for Encodable and Encoder infallible.
There are two impls of the `Encoder` trait: `opaque::Encoder` and
`opaque::FileEncoder`. The former encodes into memory and is infallible, the
latter writes to file and is fallible.

Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a
bit verbose and has non-trivial cost, which is annoying given how rare failures
are (especially in the infallible `opaque::Encoder` case).

This commit changes how `Encoder` fallibility is handled. All the `emit_*`
methods are now infallible. `opaque::Encoder` requires no great changes for
this. `opaque::FileEncoder` now implements a delayed error handling strategy.
If a failure occurs, it records this via the `res` field, and all subsequent
encoding operations are skipped if `res` indicates an error has occurred. Once
encoding is complete, the new `finish` method is called, which returns a
`Result`. In other words, there is now a single `Result`-producing method
instead of many of them.

This has very little effect on how any file errors are reported if
`opaque::FileEncoder` has any failures.

Much of this commit is boring mechanical changes, removing `Result` return
values and `?` or `unwrap` from expressions. The more interesting parts are as
follows.
- serialize.rs: The `Encoder` trait gains an `Ok` associated type. The
  `into_inner` method is changed into `finish`, which returns
  `Result<Vec<u8>, !>`.
- opaque.rs: The `FileEncoder` adopts the delayed error handling
  strategy. Its `Ok` type is a `usize`, returning the number of bytes
  written, replacing previous uses of `FileEncoder::position`.
- Various methods that take an encoder now consume it, rather than being
  passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-08 07:01:26 +10:00
..
consts Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
inhabitedness Move things to rustc_type_ir 2022-05-28 11:38:22 -07:00
print Fix pretty printing named bound regions under -Zverbose 2022-06-04 17:32:27 -04:00
_match.rs Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk" 2022-03-28 16:27:14 +00:00
adjustment.rs fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
adt.rs only_local: always check for misuse 2022-05-10 12:07:35 +02:00
assoc.rs Cache more queries on disk. 2022-05-13 08:06:48 +02:00
binding.rs words 2020-11-16 22:42:09 +01:00
cast.rs Use rustc_type_ir::{IntTy,UintTy,FloatTy} instead of the rustc_ast` ones in types 2021-01-18 21:09:23 +01:00
closure.rs fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
codec.rs Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
consts.rs Initial fixes on top of type interner commit 2022-05-28 11:38:22 -07:00
context.rs Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
diagnostics.rs On E0204 suggest missing type param bounds 2022-06-02 12:54:04 -07:00
erase_regions.rs initial revert 2022-01-15 01:16:55 +00:00
error.rs Do leak check after function ptr coercion 2022-05-22 11:18:36 -04:00
fast_reject.rs Fix TyKind lint, make consts no longer fn, etc 2022-05-28 11:38:22 -07:00
flags.rs Remove opaque type obligation and just register opaque types as they are encountered. 2022-03-28 16:57:45 +00:00
fold.rs Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes 2022-05-10 14:50:31 +00:00
generics.rs add new emit_inference_failure_err 2022-06-02 10:19:15 +02:00
impls_ty.rs rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory 2022-05-26 10:11:58 +02:00
instance.rs Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk 2022-05-14 23:53:11 +00:00
layout.rs Add support for emitting functions with coldcc in LLVM 2022-05-30 00:19:23 -07:00
list.rs Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
mod.rs Iterate over maybe_unused_trait_imports when checking dead trait imports 2022-06-04 12:38:55 -07:00
normalize_erasing_regions.rs Introduce EarlyBinder 2022-05-10 22:47:18 -04:00
parameterized.rs Make Lazy not care about lifetimes until decode 2022-05-24 15:54:44 -07:00
query.rs Rollup merge of #97312 - cjgillot:no-path-in-scope, r=compiler-errors 2022-06-06 14:34:55 +02:00
relate.rs Add bound_type_of 2022-05-13 18:27:18 -04:00
rvalue_scopes.rs factor out the rvalue lifetime rule 2022-05-22 16:46:50 +08:00
structural_impls.rs Add bound_fn_sig 2022-05-13 18:27:40 -04:00
sty.rs Replace &Vec<_>s with &[_]s 2022-06-03 20:42:42 +04:00
subst.rs Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
trait_def.rs fix simplify_type 2022-05-18 09:00:30 +02:00
util.rs Initial fixes on top of type interner commit 2022-05-28 11:38:22 -07:00
vtable.rs Fix TyKind lint, make consts no longer fn, etc 2022-05-28 11:38:22 -07:00
walk.rs fix most compiler/ doctests 2022-05-02 17:40:30 -07:00