-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Restructure CHIP_ERROR numeric values #8179
Conversation
@kpschoedel @andreilitvin Any idea why we're not getting codesize numbers here? |
Probably because of the thing #8189 is trying to fix: no completed bloat checks in the last 13 hours! |
Size increase report for "nrfconnect-example-build" from 8b5b24f
Full report output
|
Size increase report for "esp32-example-build" from 8b5b24f
Full report output
|
Size increase report for "gn_qpg-example-build" from 8b5b24f
Full report output
|
@kpschoedel - it looks like darwin/Framwork/CHIP/ChipError.h redefines CHIP_ERROR :( @sagar-apple - any ideas how to resolve this? Eventually on large platforms (darwin, linux, ios, android) we would want CHIP_ERROR to be a class, so we ca attach line information of origin to them. This would require a 'single definition' place. |
{ | ||
heap_trace_dump(); | ||
streamer_printf(streamer_get(), "Free heap %d/%d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT), | ||
heap_caps_get_total_size(MALLOC_CAP_8BIT)); | ||
return 0; | ||
return CHIP_ERROR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHIP_NO_ERROR?
(I guess this isn't being compiled?)
CHIPError is already a class in the darwin Framework but as you've pointed out, that class doesn't map to the underlying CHIP_ERROR correctly. This is a known problem. I'm unsure if there's a straightforward solution here. Errors that we want to allow consumers of the SDK to use(for case handling and such) need to be exposed as part of the CHIPErrorDomain in ObjC, afaik that involves a redefining them (maybe we can declare the enum values to map to CHIP_ERROR values?). For all other error types, we already just map them to "unknown" and print out the underlying CHIP_ERROR in the description. As a start if we can define a underlying object for CHIP_ERROR with description and code information, I think we should be able to rewrite the ObjC CHIPError to just more directly wrap the underlying CHIP_ERROR objects while updating the values in the enum in ObjC to be equal to the raw CHIP_ERROR ones. |
For this particular PR I think we can just make the Darwin integer typedef match (assuming there are no more lurking signed/unsigned issues). |
@kpschoedel - do we need the qpg6100 changes in this PR? |
No, it's just that git and I hate each other. |
src/lib/core/CHIPError.h
Outdated
/// Construct a `CHIP_ERROR` encapsulating @a value inside the @a range. | ||
static BaseType Encapsulate(Range range, BaseType value) | ||
{ | ||
return MakeInteger(range, (value & MakeMask(kValueStart, kValueLength))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is relying on kValueStart being 0, right? Otherwise I'd expect to see:
return MakeInteger(range, (value & MakeMask(kValueStart, kValueLength))); | |
return MakeInteger(range, (value & MakeMask(0, kValueLength))); |
Otherwise you are effectively left-shifting by kValueLength after taking the bits that are already shifted by kValueLength,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch.
src/lib/core/CHIPError.h
Outdated
static constexpr BaseType MakeInteger(SdkPart part, BaseType code) | ||
{ | ||
return MakeInteger(Range::kSDK, | ||
MakeField(kSdkPartStart, static_cast<std::underlying_type<SdkPart>::type>(part)) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MakeField(kSdkPartStart, static_cast<std::underlying_type<SdkPart>::type>(part)) | | |
MakeField(kSdkPartStart, to_underlying(part)) | |
after including lib/support/TypeTraits.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's a nice addition.
src/lib/core/CHIPError.h
Outdated
template <SdkPart part, BaseType code> | ||
struct MakeSdkErrorConstant | ||
{ | ||
static_assert(FitsInField(kSdkPartLength, static_cast<std::underlying_type<SdkPart>::type>(part)), "part is too large"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_assert(FitsInField(kSdkPartLength, static_cast<std::underlying_type<SdkPart>::type>(part)), "part is too large"); | |
static_assert(FitsInField(kSdkPartLength, to_underlying(part)), "part is too large"); |
src/system/SystemError.cpp
Outdated
// CHIP_SYSTEM_LWIP_ERROR_MAX all fits inside err_t. See static_assert in | ||
// MapErrorLwIP. | ||
const err_t lError = static_cast<err_t>(-lErrorWithoutOffset); | ||
const err_t lError = static_cast<err_t>(-ChipError::GetValue(aError)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const err_t lError = static_cast<err_t>(-ChipError::GetValue(aError)); | |
const err_t lError = -static_cast<err_t>(ChipError::GetValue(aError)); |
to undo the operations we did in MapErrorLwIP, where we negated, then cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
#### Problem Large constants hurt code density on small processors, and `CHIP_ERROR` constants are very common. #### Summary of Changes The internal details of `CHIP_ERROR` numbers change so that commonly used constants are small. The new representation uses bit fields managed by a helper class, `::chip::ChipError`. Several examples have been using `CHIP_CONFIG_CORE_ERROR_MAX` as a single application-level error code. Since this no longer exists, and the new representation makes it straightforward, a portion of the `CHIP_ERROR` space is now explicitly available for SDK users. #### Testing No changes to functionality. Manual sanity test with chip-tool and all-clusters-app.
* Restructure CHIP_ERROR numeric values #### Problem Large constants hurt code density on small processors, and `CHIP_ERROR` constants are very common. #### Summary of Changes The internal details of `CHIP_ERROR` numbers change so that commonly used constants are small. The new representation uses bit fields managed by a helper class, `::chip::ChipError`. Several examples have been using `CHIP_CONFIG_CORE_ERROR_MAX` as a single application-level error code. Since this no longer exists, and the new representation makes it straightforward, a portion of the `CHIP_ERROR` space is now explicitly available for SDK users. #### Testing No changes to functionality. Manual sanity test with chip-tool and all-clusters-app. * fix examples/platform/esp32/shell_extension/heap_trace.cpp * Darwin typedef * review * zap regen
Problem
Large constants hurt code density on small processors, and
CHIP_ERROR
constants are very common.
Summary of Changes
Changed the internal structure of
CHIP_ERROR
numbers so that commonlyused constants are small. The new representation uses bit fields managed
by a helper class,
::chip::ChipError
.Several examples have been using
CHIP_CONFIG_CORE_ERROR_MAX
as asingle application-level error code. Since this no longer exists, and
the new representation makes it straightforward, a portion of the
CHIP_ERROR
space is now explicitly made available for SDK users.Converted remaining uses of
int
forCHIP_ERROR
values.Changed error constant definitions to hexadecimal to make them easier to find
given the bit field representation.
Testing
No changes to functionality. Manual sanity test with chip-tool and
all-clusters-app.