Skip to content

Commit 948c300

Browse files
committed
[executorch] Rename Program::Load to Program::load
This is a commonly-used method that violates our style guide. Differential Revision: [D49345074](https://our.internmc.facebook.com/intern/diff/D49345074/) ghstack-source-id: 200971697 Pull Request resolved: #384
1 parent 1f5e54a commit 948c300

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

runtime/executor/program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ Result<executorch_flatbuffer::ExecutionPlan*> get_execution_plan(
5959

6060
} // namespace
6161

62-
/* static */ Result<Program> Program::Load(
62+
/* static */ Result<Program> Program::load(
6363
DataLoader* loader,
6464
Program::Verification verification) {
65-
EXECUTORCH_SCOPE_PROF("Program::Load");
65+
EXECUTORCH_SCOPE_PROF("Program::load");
6666

6767
// See if the program size is in the header.
6868
size_t program_size = 0;

runtime/executor/program.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ class Program final {
7373
* @param[in] verification The type of verification to do before returning
7474
* success.
7575
*/
76-
__ET_NODISCARD static Result<Program> Load(
76+
__ET_NODISCARD static Result<Program> load(
7777
DataLoader* loader,
7878
Verification verification = Verification::Minimal);
7979

80+
/// DEPRECATED: Use the lowercase `load()` instead.
81+
__ET_DEPRECATED __ET_NODISCARD static Result<Program> Load(
82+
DataLoader* loader,
83+
Verification verification = Verification::Minimal) {
84+
return load(loader, verification);
85+
}
86+
8087
// Movable, to be compatible with Result.
8188
Program(Program&&) noexcept = default;
8289
~Program() = default;

runtime/executor/test/program_test.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ using torch::executor::testing::ProgramTestFriend;
9999
TEST_F(ProgramTest, DataParsesWithMinimalVerification) {
100100
// Parse the Program from the data.
101101
Result<Program> program =
102-
Program::Load(add_loader_.get(), Program::Verification::Minimal);
102+
Program::load(add_loader_.get(), Program::Verification::Minimal);
103103

104104
// Should have succeeded.
105105
EXPECT_EQ(program.error(), Error::Ok);
106106
}
107107

108108
TEST_F(ProgramTest, DataParsesWithInternalConsistencyVerification) {
109109
// Parse the Program from the data.
110-
Result<Program> program = Program::Load(
110+
Result<Program> program = Program::load(
111111
add_loader_.get(), Program::Verification::InternalConsistency);
112112

113113
// Should have succeeded.
@@ -139,7 +139,7 @@ TEST_F(ProgramTest, BadMagicFailsToLoad) {
139139
// Parse the Program from the data. Use minimal verification to show that
140140
// even this catches the header problem.
141141
Result<Program> program =
142-
Program::Load(&data_loader, Program::Verification::Minimal);
142+
Program::load(&data_loader, Program::Verification::Minimal);
143143

144144
// Should fail.
145145
ASSERT_EQ(program.error(), Error::InvalidProgram);
@@ -152,7 +152,7 @@ TEST_F(ProgramTest, BadMagicFailsToLoad) {
152152
{
153153
// Parse the Program from the data again.
154154
Result<Program> program =
155-
Program::Load(&data_loader, Program::Verification::Minimal);
155+
Program::load(&data_loader, Program::Verification::Minimal);
156156

157157
// Should now succeed.
158158
ASSERT_EQ(program.error(), Error::Ok);
@@ -170,7 +170,7 @@ TEST_F(ProgramTest, VerificationCatchesTruncation) {
170170
BufferDataLoader half_data_loader(full_data->data(), full_data_len / 2);
171171

172172
// Loading with full verification should fail.
173-
Result<Program> program = Program::Load(
173+
Result<Program> program = Program::load(
174174
&half_data_loader, Program::Verification::InternalConsistency);
175175
ASSERT_EQ(program.error(), Error::InvalidProgram);
176176
}
@@ -195,7 +195,7 @@ TEST_F(ProgramTest, VerificationCatchesCorruption) {
195195

196196
// Should fail to parse corrupted data when using full verification.
197197
Result<Program> program =
198-
Program::Load(&data_loader, Program::Verification::InternalConsistency);
198+
Program::load(&data_loader, Program::Verification::InternalConsistency);
199199
ASSERT_EQ(program.error(), Error::InvalidProgram);
200200
}
201201

@@ -216,14 +216,14 @@ TEST_F(ProgramTest, UnalignedProgramDataFails) {
216216

217217
// Should refuse to accept unaligned data.
218218
Result<Program> program =
219-
Program::Load(&data_loader, Program::Verification::Minimal);
219+
Program::load(&data_loader, Program::Verification::Minimal);
220220
ASSERT_NE(program.error(), Error::Ok);
221221
}
222222

223223
TEST_F(ProgramTest, LoadSegmentWithNoSegments) {
224224
// Load a program with no segments.
225225
Result<Program> program =
226-
Program::Load(add_loader_.get(), kDefaultVerification);
226+
Program::load(add_loader_.get(), kDefaultVerification);
227227
EXPECT_EQ(program.error(), Error::Ok);
228228

229229
// Loading a segment should fail.
@@ -305,7 +305,7 @@ TEST_F(ProgramTest, HeaderNotPresent) {
305305
TEST_F(ProgramTest, getMethods) {
306306
// Parse the Program from the data.
307307
Result<Program> program_res =
308-
Program::Load(multi_loader_.get(), kDefaultVerification);
308+
Program::load(multi_loader_.get(), kDefaultVerification);
309309
EXPECT_EQ(program_res.error(), Error::Ok);
310310

311311
Program program(std::move(program_res.get()));
@@ -319,3 +319,10 @@ TEST_F(ProgramTest, getMethods) {
319319
EXPECT_TRUE(res2.ok());
320320
EXPECT_EQ(strcmp(res2.get(), "forward2"), 0);
321321
}
322+
323+
// Test that the deprecated Load method (capital 'L') still works.
324+
TEST_F(ProgramTest, DEPRECATEDLoad) {
325+
// Parse the Program from the data.
326+
Result<Program> program_res = Program::Load(multi_loader_.get());
327+
EXPECT_EQ(program_res.error(), Error::Ok);
328+
}

0 commit comments

Comments
 (0)