Files
carbon-lang/toolchain/sem_ir/builtin_function_kind.h
T
Richard Smith 4a7aefefaa Add support for operators on Core.IntLiteral. (#4716)
Fixes integer builtins to produce the correct values (and not
CHECK-fail) when used on integer literals. Also adds impls to the
prelude to use the new builtins to perform operations on integer
literals.

Perhaps most importantly, this allows directly initializing `i32` values
with negative numbers, as the negation operation on integer literals now
works.

For testing I've added tests for use of literals with one operator in
each class (addition, multiplication, ordering, bitwise, etc) for which
there are distinct rules or overflow behavior, rather than exhaustively
testing all the combinations. This is aimed at finding a good tradeoff
between maintainability of the tests and thorough test coverage.

Also fixes lowering of heterogeneous shifts and comparisons. These are
currently disabled when one of the operands is an integer literal, but
we may want to allow that when the integer literal operand has a known
constant value.
2024-12-31 06:36:43 +00:00

51 lines
1.7 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_
#define CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_
#include <cstdint>
#include "common/enum_base.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::SemIR {
class File;
CARBON_DEFINE_RAW_ENUM_CLASS(BuiltinFunctionKind, std::uint8_t) {
#define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
CARBON_RAW_ENUM_ENUMERATOR(Name)
#include "toolchain/sem_ir/builtin_function_kind.def"
};
// A kind of builtin function.
class BuiltinFunctionKind : public CARBON_ENUM_BASE(BuiltinFunctionKind) {
public:
#define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
CARBON_ENUM_CONSTANT_DECL(Name)
#include "toolchain/sem_ir/builtin_function_kind.def"
// Returns the builtin function kind with the given name, or None if the name
// is unknown.
static auto ForBuiltinName(llvm::StringRef name) -> BuiltinFunctionKind;
// Determines whether this builtin function kind can have the specified
// function type.
auto IsValidType(const File& sem_ir, llvm::ArrayRef<TypeId> arg_types,
TypeId return_type) const -> bool;
// Returns whether this is a compile-time-only function.
auto IsCompTimeOnly(const File& sem_ir, llvm::ArrayRef<InstId> arg_ids,
TypeId return_type_id) const -> bool;
};
#define CARBON_SEM_IR_BUILTIN_FUNCTION_KIND(Name) \
CARBON_ENUM_CONSTANT_DEFINITION(BuiltinFunctionKind, Name)
#include "toolchain/sem_ir/builtin_function_kind.def"
} // namespace Carbon::SemIR
#endif // CARBON_TOOLCHAIN_SEM_IR_BUILTIN_FUNCTION_KIND_H_