Files
swift-mirror/lib/IRGen/WitnessIndex.h
John McCall 2ba7090fe8 Remove the extra-inhabitant value witness functions.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.

The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change.  Also, being able to access the XI count directly
should be a nice win.
2018-12-11 22:18:44 -05:00

56 lines
1.7 KiB
C++

//===--- WitnessIndex.h - Index into a witness table ------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the WitnessIndex type, used for drilling into a
// protocol witness table or value witness table.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_WITNESSINDEX_H
#define SWIFT_IRGEN_WITNESSINDEX_H
#include "swift/ABI/MetadataValues.h"
#include "swift/IRGen/ValueWitness.h"
namespace swift {
namespace irgen {
/// A class which encapsulates an index into a witness table.
class WitnessIndex {
// Negative values are indexing into the private area of a protocol witness
// table.
int Value : 31;
unsigned IsPrefix : 1;
public:
WitnessIndex() = default;
explicit WitnessIndex(int index, bool isPrefix)
: Value(index), IsPrefix(isPrefix) {}
int getValue() const { return Value; }
bool isPrefix() const { return IsPrefix; }
/// Adjust the index to refer into a protocol witness table (rather than
/// a value witness table).
WitnessIndex forProtocolWitnessTable() const {
int NewValue = Value < 0
? Value
: Value + WitnessTableFirstRequirementOffset;
return WitnessIndex(NewValue, IsPrefix);
}
};
} // end namespace irgen
} // end namespace swift
#endif